[Bug libc/31798] pidfd_getpid.c is miscompiled by GCC 6.4

hjl.tools at gmail dot com sourceware-bugzilla@sourceware.org
Sat May 25 12:00:06 GMT 2024


https://sourceware.org/bugzilla/show_bug.cgi?id=31798

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |adhemerval.zanella at linaro dot o
                   |                            |rg

--- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> ---
It is a bug in sysdeps/unix/sysv/linux/pidfd_getpid.c:

      /* Ignore invalid large values.  */
      if (INT_MULTIPLY_WRAPV (10, n, &n) 
          || INT_ADD_WRAPV (n, *l++ - '0', &n))
        return -1; 

For GCC older than GCC 7, _GL_HAS_BUILTIN_ADD_OVERFLOW is 0:

#if _GL_HAS_BUILTIN_ADD_OVERFLOW
# define INT_ADD_WRAPV(a, b, r) __builtin_add_overflow (a, b, r)
# define INT_SUBTRACT_WRAPV(a, b, r) __builtin_sub_overflow (a, b, r)
#else
# define INT_ADD_WRAPV(a, b, r) \
   _GL_INT_OP_WRAPV (a, b, r, +, _GL_INT_ADD_RANGE_OVERFLOW)
# define INT_SUBTRACT_WRAPV(a, b, r) \
   _GL_INT_OP_WRAPV (a, b, r, -, _GL_INT_SUBTRACT_RANGE_OVERFLOW)
#endif

*l++ - '0' is evaluated twice.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Glibc-bugs mailing list