public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Magne Hov via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH] gdb/source.c: Fix undefined behaviour dereferencing empty string
Date: Tue, 20 Sep 2022 13:07:42 -0600	[thread overview]
Message-ID: <87mtat6f0h.fsf@tromey.com> (raw)
In-Reply-To: <20220915183141.3484234-1-mhov@undo.io> (Magne Hov via Gdb-patches's message of "Thu, 15 Sep 2022 19:31:41 +0100")

>>>>> "Magne" == Magne Hov via Gdb-patches <gdb-patches@sourceware.org> writes:

Magne> When a source file's dirname is solely made up of directory separators
Magne> we end up trying to dereference the last character of an empty string
Magne> with std::string::back, which results in undefined behaviour. A typical
Magne> use case where this can happen is when the root directory "/" is used as
Magne> a compilation directory.

...
Magne> Fix this by checking for the empty string.

I wonder if this code should be changed to use path_join instead.
That function doesn't seem to have this bug:

      if (!ret.empty () && !IS_DIR_SEPARATOR (ret.back ()))
	  ret += '/';

thanks,
Tom

  reply	other threads:[~2022-09-20 19:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-15 18:31 Magne Hov
2022-09-20 19:07 ` Tom Tromey [this message]
2022-09-21 14:51   ` Magne Hov
2022-09-21 14:58 ` [PATCH v2] " Magne Hov
2022-09-21 15:52   ` Simon Marchi
2022-09-22 13:11     ` Magne Hov
2022-09-24  8:58   ` Magne Hov

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=87mtat6f0h.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).