]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
(_dl_addr): Fix search algorithms in dladdr(); don't assume that the
authorUlrich Drepper <drepper@redhat.com>
Fri, 27 Feb 1998 17:58:39 +0000 (17:58 +0000)
committerUlrich Drepper <drepper@redhat.com>
Fri, 27 Feb 1998 17:58:39 +0000 (17:58 +0000)
number of program headers is >0 (which is wrong for the loader
itself).

elf/dladdr.c

index 59e97837603d314b0d9ec9bfd1de8fd20a545599..f3d63f76f2aa0c041b307c2cfcb3aceed99e767c 100644 (file)
@@ -1,5 +1,5 @@
 /* dladdr -- Locate the shared object symbol nearest a given address.
-   Copyright (C) 1996 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1998 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -33,7 +33,7 @@ dladdr (void *address, Dl_info *info)
   /* Find the highest-addressed object that ADDRESS is not below.  */
   match = NULL;
   for (l = _dl_loaded; l; l = l->l_next)
-    if (addr >= l->l_addr && !match || match->l_addr < l->l_addr)
+    if (addr >= l->l_addr && (!match || match->l_addr < l->l_addr))
       match = l;
 
   if (match)
@@ -41,13 +41,19 @@ dladdr (void *address, Dl_info *info)
       /* We know ADDRESS lies within MATCH if in any shared object.
         Make sure it isn't past the end of MATCH's segments.  */
       size_t n = match->l_phnum;
-      do
-       --n;
-      while (match->l_phdr[n].p_type != PT_LOAD);
-      if (addr >= (match->l_addr +
-                  match->l_phdr[n].p_vaddr + match->l_phdr[n].p_memsz))
-       /* Off the end of the highest-addressed shared object.  */
-       return 0;
+      if (n > 0)
+       {
+         if (n > 0)
+           {
+             do
+               --n;
+             while (match->l_phdr[n].p_type != PT_LOAD);
+             if (addr >= (match->l_addr +
+                          match->l_phdr[n].p_vaddr + match->l_phdr[n].p_memsz))
+               /* Off the end of the highest-addressed shared object.  */
+               return 0;
+           }
+       }
     }
   else
     return 0;