[uClibc] uwoody fix for libglib

Garrett Kajmowicz gkajmowi at tbaytel.net
Fri Jul 9 16:57:54 UTC 2004


There is a problem with the vanilla libglib code which uses an unchecked 
return value from a call to sysconf.  The call attempts to find out how much 
memory is required to hold a line of the password file.  however, the call is 
unimplemented and returns -1.  This value is then passed, unchecked, to 
malloc, which of course fails.

The assumption that the return value would succeed is reasonable as there is a 
define statement which implies that the particular call works.

I have written a patch which fixes the problem. Please implement it for future 
versions of the glib package.  The patch moves one variable declarationm and 
adds an 'if' statement to handle invalid values.

-	Garrett Kajmowicz

diff -Naur glib-vanilla/gutils.c glib-1.2.10/gutils.c
--- glib-vanilla/gutils.c       2000-08-09 18:12:31.000000000 +0000
+++ glib-1.2.10/gutils.c        2004-07-09 16:42:50.000000000 +0000
@@ -480,13 +480,15 @@

 #  ifdef HAVE_GETPWUID_R
         struct passwd pwd;
+        gint error;
 #    ifdef _SC_GETPW_R_SIZE_MAX
         /* This reurns the maximum length */
-        guint bufsize = sysconf (_SC_GETPW_R_SIZE_MAX);
+        gint bufsize = sysconf (_SC_GETPW_R_SIZE_MAX);
+        if(bufsize < 1)
+           bufsize = 64;      /*Same length as below*/
 #    else /* _SC_GETPW_R_SIZE_MAX */
-        guint bufsize = 64;
+        gint bufsize = 64;
 #    endif /* _SC_GETPW_R_SIZE_MAX */
-        gint error;

         do
           {



More information about the uClibc mailing list