Fixed
Created: Jun 21, 2022
Updated: Nov 10, 2022
Resolved Date: Oct 17, 2022
Found In Version: 10.21.20.14
Fix Version: 10.21.20.14
Severity: Standard
Applicable for: Wind River Linux LTS 21
Component/s: Userspace
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 either
If (ret >= 0 || errno != ENOSYS)
return ret;
or more readable and less error-prone (IMO):
if (ret != -1 || errno != ENOSYS)
return ret;