mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
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	[thread overview]
Message-ID: <20190619163011.GT1506@brightrain.aerifal.cx> (raw)
In-Reply-To: <869863DB5440B44FB22173F42FC3F3CE01D0843A@dggemm513-mbx.china.huawei.com>

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 <liucheng32@huawei.com<mailto:liucheng32@huawei.com>>
> 
> ---
> 
> 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


  reply	other threads:[~2019-06-19 16:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-19  7:13 liucheng (G)
2019-06-19 16:30 ` Rich Felker [this message]
2019-06-20  3:50 liucheng (G)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190619163011.GT1506@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).