From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14249 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] The local variables "sym" and "bestsym" in dladdr function are assigned initial values to NULL Date: Wed, 19 Jun 2019 12:30:11 -0400 Message-ID: <20190619163011.GT1506@brightrain.aerifal.cx> References: <869863DB5440B44FB22173F42FC3F3CE01D0843A@dggemm513-mbx.china.huawei.com> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="166836"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-14265-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jun 19 18:30:27 2019 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.89) (envelope-from ) id 1hddTf-000hBu-1D for gllmg-musl@m.gmane.org; Wed, 19 Jun 2019 18:30:27 +0200 Original-Received: (qmail 5406 invoked by uid 550); 19 Jun 2019 16:30:24 -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 5385 invoked from network); 19 Jun 2019 16:30:23 -0000 Content-Disposition: inline In-Reply-To: <869863DB5440B44FB22173F42FC3F3CE01D0843A@dggemm513-mbx.china.huawei.com> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:14249 Archived-At: On Wed, Jun 19, 2019 at 07:13:18AM +0000, liucheng (G) wrote: > Dear all, > > > > The code bellow in the dladdr function has different behaviors at different optimization levels. > > 2219 if (bestsym && besterr > bestsym->st_size-1) { The underlying problem is that its behavior is undefined due to access to an uninitialized object. This was introduced in commit c8b49b2fbc7faa8bf065220f11963d76c8a2eb93, and seems to just be a mistake; the condition should have been best && ..., not bestsym && ... > [patch] > > Signed-off-by: l00383200 > > > --- > > ldso/dynlink.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/ldso/dynlink.c b/ldso/dynlink.c > > index 7cb66db..c5f5fb7 100644 > > --- a/ldso/dynlink.c > > +++ b/ldso/dynlink.c Your mail system seems to have botched the inline patch. If it can't send clean plaintext, please use attachments. > @@ -2175,7 +2175,8 @@ int dladdr(const void *addr_arg, Dl_info *info) > > { > > size_t addr = (size_t)addr_arg; > > struct dso *p; > > - Sym *sym, *bestsym; > > + Sym *sym = NULL; > > + Sym *bestsym = NULL; For future reference, NULL isn't used in musl style, just 0. There are a few places it's still present but being phased out. But I think here the right fix is probably correcting the conditional, not adding extra initializations. Leaving the initialization out makes it possible for static analysis tools to find bugs like the one you found. I'm kinda surprised none (or even just normal compiler warnings) had caught it yet. Rich