* Suspected bug in mq_timedreceive
@ 2022-06-30 6:37 sundeep.kokkonda
2022-06-30 11:10 ` Adhemerval Zanella
0 siblings, 1 reply; 2+ messages in thread
From: sundeep.kokkonda @ 2022-06-30 6:37 UTC (permalink / raw)
To: libc-help, libc-help-info, libc-alpha, libc-alpha-info
Hello,
The mq_timedreceive code in
glibc-2.33/sysdeps/unix/sysv/linux/mq_timedreceive.c does this:
ssize_t
_mq_timedreceive_time64 (mqd_t mqdes, char *_restrict msg_ptr, size_t
msg_len,
unsigned int *__restrict msg_prio,
const struct _timespec64 *_restrict abs_timeout)
{
#ifndef __NR_mq_timedreceive_time64
#define __NR_mq_timedreceive_time64 __NR_mq_timedreceive
#endif
int ret = SYSCALL_CANCEL (mq_timedreceive_time64, mqdes, msg_ptr, msg_len,
msg_prio, abs_timeout);
#ifndef __ASSUME_TIME64_SYSCALLS
if (ret == 0 || errno != ENOSYS)
return ret;
struct timespec ts32;
if (abs_timeout != NULL)
{
if (! in_time_t_range (abs_timeout->tv_sec))
{ __set_errno (EOVERFLOW); return -1; }
ts32 = valid_timespec64_to_timespec (*abs_timeout);
}
ret = SYSCALL_CANCEL (mq_timedreceive, mqdes, msg_ptr, msg_len, msg_prio,
abs_timeout != NULL ? &ts32 : NULL);
#endif
return ret;
}
This test is wrong:
if (ret == 0 || errno != ENOSYS)
return ret;
That test would be correct if mq_timedreceive returned 0 on success, as is
the case for mq_timedsend. However, mq_timedreceive actually returns the
number of bytes read, so the correct test is:
If (ret >= 0 || errno != ENOSYS)
return ret;
@community: Can you comment on this, whether it is a bug or implemented
intentionally for any specific reason? I checked the latest glibc-2.35
sources as well, the check for ret==0 is still the same.
Thanks,
Sundeep K.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Suspected bug in mq_timedreceive
2022-06-30 6:37 Suspected bug in mq_timedreceive sundeep.kokkonda
@ 2022-06-30 11:10 ` Adhemerval Zanella
0 siblings, 0 replies; 2+ messages in thread
From: Adhemerval Zanella @ 2022-06-30 11:10 UTC (permalink / raw)
To: sundeep.kokkonda; +Cc: libc-help, libc-help-info, libc-alpha, libc-alpha-info
> On 30 Jun 2022, at 03:37, sundeep.kokkonda--- via Libc-help <libc-help@sourceware.org> wrote:
>
> Hello,
>
>
>
> The mq_timedreceive code in
> glibc-2.33/sysdeps/unix/sysv/linux/mq_timedreceive.c does this:
>
>
>
> ssize_t
>
> _mq_timedreceive_time64 (mqd_t mqdes, char *_restrict msg_ptr, size_t
> msg_len,
>
> unsigned int *__restrict msg_prio,
>
> const struct _timespec64 *_restrict abs_timeout)
>
> {
>
> #ifndef __NR_mq_timedreceive_time64
>
> #define __NR_mq_timedreceive_time64 __NR_mq_timedreceive
>
> #endif
>
> int ret = SYSCALL_CANCEL (mq_timedreceive_time64, mqdes, msg_ptr, msg_len,
>
> msg_prio, abs_timeout);
>
> #ifndef __ASSUME_TIME64_SYSCALLS
>
> if (ret == 0 || errno != ENOSYS)
>
> return ret;
>
>
>
> struct timespec ts32;
>
> if (abs_timeout != NULL)
>
> {
>
> if (! in_time_t_range (abs_timeout->tv_sec))
>
>
>
>
>
> { __set_errno (EOVERFLOW); return -1; }
>
> ts32 = valid_timespec64_to_timespec (*abs_timeout);
>
> }
>
>
>
> ret = SYSCALL_CANCEL (mq_timedreceive, mqdes, msg_ptr, msg_len, msg_prio,
>
> abs_timeout != NULL ? &ts32 : NULL);
>
> #endif
>
>
>
> return ret;
>
> }
>
>
>
> This test is wrong:
>
>
>
> if (ret == 0 || errno != ENOSYS)
>
> return ret;
>
>
>
> That test would be correct if mq_timedreceive returned 0 on success, as is
> the case for mq_timedsend. However, mq_timedreceive actually returns the
> number of bytes read, so the correct test is:
>
>
>
> If (ret >= 0 || errno != ENOSYS)
>
> return ret;
Yeah, this is incorrect. I will open a bug an fix it on all affected releases.
At least for 2.36 the time64 code path is only used if the target date can not
be fit in 32-bit time_t.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-06-30 11:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-30 6:37 Suspected bug in mq_timedreceive sundeep.kokkonda
2022-06-30 11:10 ` Adhemerval Zanella
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).