This is the mail archive of the glibc-bugs@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/263] New: potential subscript error and superfluous test in Linux getloadavg


While fixing some bugs in gnulib getloadavg I discovered that glibc
Linux getloadavg.c has a bug when the read returns EOF, and an
unnecessary test.  Here's a proposed patch.

2004-07-12  Paul Eggert  <eggert@cs.ucla.edu>

	* sysdeps/unix/sysv/linux/getloadavg.c (getloadavg): Don't store
	outside the buffer if the read returns 0.  __strtod_l can't set
	endp to NULL, so remove a test for that case.

--- old/sysdeps/unix/sysv/linux/getloadavg.c	2003-09-03 13:11:54 -0700
+++ new/sysdeps/unix/sysv/linux/getloadavg.c	2004-07-12 11:17:39 -0700
@@ -45,7 +45,7 @@ getloadavg (double loadavg[], int nelem)
 
       nread = read_not_cancel (fd, buf, sizeof buf - 1);
       close_not_cancel_no_status (fd);
-      if (nread < 0)
+      if (nread <= 0)
 	return -1;
       buf[nread - 1] = '\0';
 
@@ -56,7 +56,7 @@ getloadavg (double loadavg[], int nelem)
 	{
 	  char *endp;
 	  loadavg[i] = __strtod_l (p, &endp, &_nl_C_locobj);
-	  if (endp == NULL || endp == p)
+	  if (endp == p)
 	    /* This should not happen.  The format of /proc/loadavg
 	       must have changed.  Don't return with what we have,
 	       signal an error.  */

-- 
           Summary: potential subscript error and superfluous test in Linux
                    getloadavg
           Product: glibc
           Version: 2.3.3
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: gotom at debian dot or dot jp
        ReportedBy: eggert at gnu dot org
                CC: glibc-bugs at sources dot redhat dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://sources.redhat.com/bugzilla/show_bug.cgi?id=263

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]