Fix parsing of /sys/devices/system/cpu/online (bug 27038)

Message ID 87im9b3wbi.fsf@igel.home
State New
Headers show
Series
  • Fix parsing of /sys/devices/system/cpu/online (bug 27038)
Related show

Commit Message

Andreas Schwab Dec. 9, 2020, 2:09 p.m.
The file contains comma-separated ranges, not spaces.
---
 sysdeps/unix/sysv/linux/getsysstats.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

-- 
2.29.2


-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

Comments

Adhemerval Zanella via Libc-alpha Dec. 9, 2020, 2:15 p.m. | #1
* Andreas Schwab:

> The file contains comma-separated ranges, not spaces.


Bug 27038 is a duplicate of bug 25859.

> ---

>  sysdeps/unix/sysv/linux/getsysstats.c | 5 +++--

>  1 file changed, 3 insertions(+), 2 deletions(-)

>

> diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c

> index 1ef077f9af..a9069b7056 100644

> --- a/sysdeps/unix/sysv/linux/getsysstats.c

> +++ b/sysdeps/unix/sysv/linux/getsysstats.c

> @@ -143,6 +143,7 @@ __get_nprocs (void)

>    char *re = buffer_end;

>  

>    const int flags = O_RDONLY | O_CLOEXEC;

> +  /* This file contains comma-separated ranges.  */

>    int fd = __open_nocancel ("/sys/devices/system/cpu/online", flags);

>    char *l;

>    int result = 0;

> @@ -175,10 +176,10 @@ __get_nprocs (void)

>  	    result += m - n + 1;

>  

>  	    l = endp;

> -	    while (l < re && isspace (*l))

> +	    if (l < re && *l == ',')

>  	      ++l;

>  	  }

> -	while (l < re);

> +	while (l < re && *l != '\n');

>  

>        __close_nocancel_nostatus (fd);

>  

> -- 


The actual patch looks okay to me.

Thanks,
Florian
-- 
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill

Patch

diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c
index 1ef077f9af..a9069b7056 100644
--- a/sysdeps/unix/sysv/linux/getsysstats.c
+++ b/sysdeps/unix/sysv/linux/getsysstats.c
@@ -143,6 +143,7 @@  __get_nprocs (void)
   char *re = buffer_end;
 
   const int flags = O_RDONLY | O_CLOEXEC;
+  /* This file contains comma-separated ranges.  */
   int fd = __open_nocancel ("/sys/devices/system/cpu/online", flags);
   char *l;
   int result = 0;
@@ -175,10 +176,10 @@  __get_nprocs (void)
 	    result += m - n + 1;
 
 	    l = endp;
-	    while (l < re && isspace (*l))
+	    if (l < re && *l == ',')
 	      ++l;
 	  }
-	while (l < re);
+	while (l < re && *l != '\n');
 
       __close_nocancel_nostatus (fd);