This is the mail archive of the libc-alpha@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]

[patch] dlfcn/dlerror.c: dlerror(): Check for result->errstring being NULL


The problem appeared when dlerror() was called before anything was
dlopen()'d ("int main() {dlerror();}"), which caused a segfault. The
problem was that last_result is unitialized at this point, and that case
isn't checked for before trying to strcmp result->errstring. This patch
fixes that case, and returns NULL, just as if there were no errors
(which there aren't).

2001-01-01  Ben Collins  <bcollins@debian.org>

	* dlfcn/dlerror.c: dlerror(): Check for result->errstring being
	  NULL.

-- 
 -----------=======-=-======-=========-----------=====------------=-=------
/  Ben Collins  --  ...on that fantastic voyage...  --  Debian GNU/Linux   \
`  bcollins@debian.org  --  bcollins@openldap.org  --  bcollins@linux.com  '
 `---=========------=======-------------=-=-----=-===-======-------=--=---'
Index: dlerror.c
===================================================================
RCS file: /cvs/glibc/libc/dlfcn/dlerror.c,v
retrieving revision 1.7
diff -u -u -r1.7 dlerror.c
--- dlerror.c	2000/12/28 00:47:19	1.7
+++ dlerror.c	2001/01/01 22:44:31
@@ -54,16 +54,17 @@
   if (result == NULL)
     result = &last_result;
 
-  /* Test whether we already returned the string.  */
-  if (result->returned != 0)
+  if (result->errstring == NULL)
     {
-      /* We can now free the string.  */
-      if (result->errstring != NULL)
-	{
-	  if (strcmp (result->errstring, "out of memory") != 0)
-	    free ((char *) result->errstring);
-	  result->errstring = NULL;
-	}
+      /* There doesn't appear to be any errors.  */
+      buf = NULL;
+    }
+  else if (result->returned != 0)
+    {
+      /* Since we already returned the string we can now free it.  */
+      if (strcmp (result->errstring, "out of memory") != 0)
+	free ((char *) result->errstring);
+      result->errstring = NULL;
       buf = NULL;
     }
   else

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