From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12675 Path: news.gmane.org!.POSTED!not-for-mail From: "Siebenborn, Axel" Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] dl_addr: compare addr with sym->st_size. Date: Tue, 3 Apr 2018 13:06:09 +0000 Message-ID: <6a42ca4b6c9b4ea08925e232d7b57667@sap.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1522760663 27744 195.159.176.226 (3 Apr 2018 13:04:23 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 3 Apr 2018 13:04:23 +0000 (UTC) To: "musl@lists.openwall.com" Original-X-From: musl-return-12689-gllmg-musl=m.gmane.org@lists.openwall.com Tue Apr 03 15:04:19 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1f3Lbn-00077Q-BN for gllmg-musl@m.gmane.org; Tue, 03 Apr 2018 15:04:19 +0200 Original-Received: (qmail 7506 invoked by uid 550); 3 Apr 2018 13:06:22 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 7469 invoked from network); 3 Apr 2018 13:06:21 -0000 Thread-Topic: [PATCH] dl_addr: compare addr with sym->st_size. Thread-Index: AdPLTEBvr5Sbu89kTKWUonO61LEwTw== Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.21.23.236] Xref: news.gmane.org gmane.linux.lib.musl.general:12675 Archived-At: Hi, this patch fixes a problem with dl_addr. We found symbols, in cases we should not find a symbol, since the compariso= n with sym->st_size is missing. According to the spec, dl_addr should not return an error in this case. Ins= tead 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 =3D 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 =3D symaddr; bestsym =3D sym; @@ -1967,13 +1967,16 @@ int dladdr(const void *addr, Dl_info *info) } } =20 - if (!best) return 0; - - if (DL_FDPIC && (bestsym->st_info&0xf) =3D=3D STT_FUNC) - best =3D p->funcdescs + (bestsym - p->syms); - info->dli_fname =3D p->name; info->dli_fbase =3D p->map; + if (!best) { + info->dli_sname =3D 0; + info->dli_saddr =3D 0; + return 0 + } + + if ( DL_FDPIC && (bestsym->st_info&0xf) =3D=3D STT_FUNC) + best =3D p->funcdescs + (bestsym - p->syms); info->dli_sname =3D strings + bestsym->st_name; info->dli_saddr =3D best;