This is the mail archive of the libc-hacker@sourceware.org mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


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

[PATCH] Don't look at freed memory in dl-deps.c


Hi!

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=178159
verified with valgrind on elf/neededtest4.
_dl_catch_error might allocate objname in the same memory block as errstring
(right after its terminating '\0'), so after free ((char *) errstring)
shouldn't be used.  But it is passed down to _dl_signal_error.
  if (errno_reason)
    _dl_signal_error (errno_reason == -1 ? 0 : errno_reason, objname,
                      NULL, errstring);
Fixed by making a local copy, verified with valgrind.

2006-01-18  Jakub Jelinek  <jakub@redhat.com>

	* elf/dl-deps.c (_dl_map_object_deps): In case of failure also make a
	copy of objname string.

--- libc/elf/dl-deps.c.jj	2005-06-22 18:34:11.000000000 +0200
+++ libc/elf/dl-deps.c	2006-01-18 10:28:34.000000000 +0100
@@ -247,6 +247,7 @@ _dl_map_object_deps (struct link_map *ma
 		if (__builtin_expect (errstring != NULL, 0))
 		  {
 		    char *new_errstring = strdupa (errstring);
+		    objname = strdupa (objname);
 		    if (malloced)
 		      free ((char *) errstring);
 		    errstring = new_errstring;
@@ -337,6 +338,7 @@ _dl_map_object_deps (struct link_map *ma
 		    if (__builtin_expect (errstring != NULL, 0))
 		      {
 			char *new_errstring = strdupa (errstring);
+			objname = strdupa (objname);
 			if (malloced)
 			  free ((char *) errstring);
 			errstring = new_errstring;

	Jakub


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