mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] dl_addr: compare addr with sym->st_size.
@ 2018-04-03 13:06 Siebenborn, Axel
  2018-04-10  7:22 ` FW: " Siebenborn, Axel
       [not found] ` <20180410142312.GE3094@brightrain.aerifal.cx>
  0 siblings, 2 replies; 10+ messages in thread
From: Siebenborn, Axel @ 2018-04-03 13:06 UTC (permalink / raw)
  To: musl

Hi,
this patch fixes a problem with dl_addr.

We found symbols, in cases we should not find a symbol, since the comparison with sym->st_size is missing.

According to the spec, dl_addr should not return an error in this case. Instead dli_sname and dli_addr should be set to NULL.

Regards,
Axel

diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index 9bf6924..cc87dc0 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -1958,7 +1958,7 @@ int dladdr(const void *addr, Dl_info *info)
                 && (1<<(sym->st_info&0xf) & OK_TYPES)
                 && (1<<(sym->st_info>>4) & OK_BINDS)) {
                        void *symaddr = laddr(p, sym->st_value);
-                       if (symaddr > addr || symaddr < best)
+                       if (symaddr > addr || (void*) ((uint8_t*) symaddr + sym->st_size) < addr || symaddr < best)
                                continue;
                        best = symaddr;
                        bestsym = sym;
@@ -1967,13 +1967,16 @@ int dladdr(const void *addr, Dl_info *info)
                }
        }
 
-       if (!best) return 0;
-
-       if (DL_FDPIC && (bestsym->st_info&0xf) == STT_FUNC)
-               best = p->funcdescs + (bestsym - p->syms);
-
        info->dli_fname = p->name;
        info->dli_fbase = p->map;
+       if (!best) {
+               info->dli_sname = 0;
+               info->dli_saddr = 0;
+               return 0
+       }
+
+       if ( DL_FDPIC && (bestsym->st_info&0xf) == STT_FUNC)
+               best = p->funcdescs + (bestsym - p->syms);
        info->dli_sname = strings + bestsym->st_name;
        info->dli_saddr = best;


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-06-28 15:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-03 13:06 [PATCH] dl_addr: compare addr with sym->st_size Siebenborn, Axel
2018-04-10  7:22 ` FW: " Siebenborn, Axel
     [not found] ` <20180410142312.GE3094@brightrain.aerifal.cx>
2018-04-11  8:07   ` Siebenborn, Axel
2018-04-13  1:01     ` Rich Felker
2018-04-13 10:16       ` Siebenborn, Axel
2018-05-16  8:16         ` Siebenborn, Axel
2018-05-16 23:16           ` Rich Felker
2018-05-17  2:06             ` William Pitcock
2018-06-27 20:02             ` Rich Felker
2018-06-28 15:51               ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).