Suspected bug in mq_timedreceive

sundeep.kokkonda@gmail.com sundeep.kokkonda@gmail.com
Thu Jun 30 06:37:26 GMT 2022


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.



More information about the Libc-alpha mailing list