[v3] linux: __get_nprocs_sched: do not feed CPU_COUNT_S with garbage [BZ #28850]

Message ID 20220201224446.547264-1-glebfm@altlinux.org
State Committed
Commit 97ba273b505763325efd802dc3a9562dbba79579
Headers
Series [v3] linux: __get_nprocs_sched: do not feed CPU_COUNT_S with garbage [BZ #28850] |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Gleb Fotengauer-Malinovskiy Feb. 1, 2022, 10:44 p.m. UTC
  Pass the actual number of bytes returned by the kernel.

Fixes: 33099d72e41c ("linux: Simplify get_nprocs")
---
 sysdeps/unix/sysv/linux/getsysstats.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Dmitry V. Levin Feb. 1, 2022, 10:46 p.m. UTC | #1
On Tue, Feb 01, 2022 at 10:44:46PM +0000, Gleb Fotengauer-Malinovskiy wrote:
> Pass the actual number of bytes returned by the kernel.
> 
> Fixes: 33099d72e41c ("linux: Simplify get_nprocs")
> ---
>  sysdeps/unix/sysv/linux/getsysstats.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c
> index 4798cc337e..c98c8ce3d4 100644
> --- a/sysdeps/unix/sysv/linux/getsysstats.c
> +++ b/sysdeps/unix/sysv/linux/getsysstats.c
> @@ -44,7 +44,7 @@ __get_nprocs_sched (void)
>    int r = INTERNAL_SYSCALL_CALL (sched_getaffinity, 0, cpu_bits_size,
>  				 cpu_bits);
>    if (r > 0)
> -    return CPU_COUNT_S (cpu_bits_size, (cpu_set_t*) cpu_bits);
> +    return CPU_COUNT_S (r, (cpu_set_t*) cpu_bits);
>    else if (r == -EINVAL)
>      /* The input buffer is still not enough to store the number of cpus.  This
>         is an arbitrary values assuming such systems should be rare and there

Reviewed-by: Dmitry V. Levin <ldv@altlinux.org>
  

Patch

diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c
index 4798cc337e..c98c8ce3d4 100644
--- a/sysdeps/unix/sysv/linux/getsysstats.c
+++ b/sysdeps/unix/sysv/linux/getsysstats.c
@@ -44,7 +44,7 @@  __get_nprocs_sched (void)
   int r = INTERNAL_SYSCALL_CALL (sched_getaffinity, 0, cpu_bits_size,
 				 cpu_bits);
   if (r > 0)
-    return CPU_COUNT_S (cpu_bits_size, (cpu_set_t*) cpu_bits);
+    return CPU_COUNT_S (r, (cpu_set_t*) cpu_bits);
   else if (r == -EINVAL)
     /* The input buffer is still not enough to store the number of cpus.  This
        is an arbitrary values assuming such systems should be rare and there