parse_fdinfo: Don't advance pointer twice [BZ #31798]
Checks
Context |
Check |
Description |
redhat-pt-bot/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
redhat-pt-bot/TryBot-32bit |
success
|
Build for i686
|
linaro-tcwg-bot/tcwg_glibc_build--master-arm |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_glibc_check--master-arm |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 |
success
|
Testing passed
|
Commit Message
pidfd_getpid.c has
/* 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, INT_ADD_WRAPV(a, b, r) is defined as
_GL_INT_OP_WRAPV (a, b, r, +, _GL_INT_ADD_RANGE_OVERFLOW)
and *l++ - '0' is evaluated twice. Fix BZ #31798 by moving "l++" out of
the if statement. Tested with GCC 6.4 and GCC 14.1.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
sysdeps/unix/sysv/linux/pidfd_getpid.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
Comments
On 25/05/24 09:13, H.J. Lu wrote:
> pidfd_getpid.c has
>
> /* 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, INT_ADD_WRAPV(a, b, r) is defined as
>
> _GL_INT_OP_WRAPV (a, b, r, +, _GL_INT_ADD_RANGE_OVERFLOW)
>
> and *l++ - '0' is evaluated twice. Fix BZ #31798 by moving "l++" out of
> the if statement. Tested with GCC 6.4 and GCC 14.1.
>
> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
The intprops.h is clear about it:
341 These macros may evaluate their arguments zero or multiple times, so the
342 arguments should not have side effects.
LGTM, thanks.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> sysdeps/unix/sysv/linux/pidfd_getpid.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/sysdeps/unix/sysv/linux/pidfd_getpid.c b/sysdeps/unix/sysv/linux/pidfd_getpid.c
> index ebcbe8fdf6..6967477fab 100644
> --- a/sysdeps/unix/sysv/linux/pidfd_getpid.c
> +++ b/sysdeps/unix/sysv/linux/pidfd_getpid.c
> @@ -74,8 +74,10 @@ parse_fdinfo (const char *l, void *arg)
>
> /* Ignore invalid large values. */
> if (INT_MULTIPLY_WRAPV (10, n, &n)
> - || INT_ADD_WRAPV (n, *l++ - '0', &n))
> + || INT_ADD_WRAPV (n, *l - '0', &n))
> return -1;
> +
> + l++;
> }
>
> /* -1 indicates that the process is terminated. */
@@ -74,8 +74,10 @@ parse_fdinfo (const char *l, void *arg)
/* Ignore invalid large values. */
if (INT_MULTIPLY_WRAPV (10, n, &n)
- || INT_ADD_WRAPV (n, *l++ - '0', &n))
+ || INT_ADD_WRAPV (n, *l - '0', &n))
return -1;
+
+ l++;
}
/* -1 indicates that the process is terminated. */