From: Andrew Burgess <aburgess@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: Ping: Re: [PATCH] libiberty/buildargv: POSIX behaviour for backslash handling
Date: Tue, 02 Jan 2024 11:22:30 +0000 [thread overview]
Message-ID: <87a5po9dzd.fsf@redhat.com> (raw)
In-Reply-To: <24a8d878590403540bc9b579ba58805985a4d2f7.1701881419.git.aburgess@redhat.com>
Ping!
Thanks,
Andrew
Andrew Burgess <aburgess@redhat.com> writes:
> GDB makes use of the libiberty function buildargv for splitting the
> inferior (program being debugged) argument string in the case where
> the inferior is not being started under a shell.
>
> I have recently been working to improve this area of GDB, and have
> tracked done some of the unexpected behaviour to the libiberty
> function buildargv, and how it handles backslash escapes.
>
> For reference, I've been mostly reading:
>
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
>
> The issues that I would like to fix are:
>
> 1. Backslashes within single quotes should not be treated as an
> escape, thus: '\a' should split to \a, retaining the backslash.
>
> 2. Backslashes within double quotes should only act as an escape if
> they are immediately before one of the characters $ (dollar),
> ` (backtick), " (double quote), ` (backslash), or \n (newline). In
> all other cases a backslash should not be treated as an escape
> character. Thus: "\a" should split to \a, but "\$" should split to
> $.
>
> 3. A backslash-newline sequence should be treated as a line
> continuation, both the backslash and the newline should be removed.
>
> I've updated libiberty and also added some tests. All the existing
> libiberty tests continue to pass, but I'm not sure if there is more
> testing that should be done, buildargv is used within lto-wraper.cc,
> so maybe there's some testing folk can suggest that I run?
> ---
> libiberty/argv.c | 8 +++++--
> libiberty/testsuite/test-expandargv.c | 34 +++++++++++++++++++++++++++
> 2 files changed, 40 insertions(+), 2 deletions(-)
>
> diff --git a/libiberty/argv.c b/libiberty/argv.c
> index c2823d3e4ba..6bae4ca2ee9 100644
> --- a/libiberty/argv.c
> +++ b/libiberty/argv.c
> @@ -224,9 +224,13 @@ char **buildargv (const char *input)
> if (bsquote)
> {
> bsquote = 0;
> - *arg++ = *input;
> + if (*input != '\n')
> + *arg++ = *input;
> }
> - else if (*input == '\\')
> + else if (*input == '\\'
> + && !squote
> + && (!dquote
> + || strchr ("$`\"\\\n", *(input + 1)) != NULL))
> {
> bsquote = 1;
> }
> diff --git a/libiberty/testsuite/test-expandargv.c b/libiberty/testsuite/test-expandargv.c
> index 30f2337ef77..b8dcc6a269a 100644
> --- a/libiberty/testsuite/test-expandargv.c
> +++ b/libiberty/testsuite/test-expandargv.c
> @@ -142,6 +142,40 @@ const char *test_data[] = {
> "b",
> 0,
>
> + /* Test 7 - No backslash removal within single quotes. */
> + "'a\\$VAR' '\\\"'", /* Test 7 data */
> + ARGV0,
> + "@test-expandargv-7.lst",
> + 0,
> + ARGV0,
> + "a\\$VAR",
> + "\\\"",
> + 0,
> +
> + /* Test 8 - Remove backslash / newline pairs. */
> + "\"ab\\\ncd\" ef\\\ngh", /* Test 8 data */
> + ARGV0,
> + "@test-expandargv-8.lst",
> + 0,
> + ARGV0,
> + "abcd",
> + "efgh",
> + 0,
> +
> + /* Test 9 - Backslash within double quotes. */
> + "\"\\$VAR\" \"\\`\" \"\\\"\" \"\\\\\" \"\\n\" \"\\t\"", /* Test 9 data */
> + ARGV0,
> + "@test-expandargv-9.lst",
> + 0,
> + ARGV0,
> + "$VAR",
> + "`",
> + "\"",
> + "\\",
> + "\\n",
> + "\\t",
> + 0,
> +
> 0 /* Test done marker, don't remove. */
> };
>
>
> base-commit: 458e7c937924bbcef80eb006af0b61420dbfc1c1
> --
> 2.25.4
next prev parent reply other threads:[~2024-01-02 11:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-06 16:50 Andrew Burgess
2024-01-02 11:22 ` Andrew Burgess [this message]
2024-02-10 17:25 ` [PATCHv2 0/2] Changes to libiberty buildargv Andrew Burgess
2024-02-10 17:26 ` [PATCHv2 1/2] libiberty/buildargv: POSIX behaviour for backslash handling Andrew Burgess
2024-05-26 15:03 ` Jeff Law
2024-02-10 17:26 ` [PATCHv2 2/2] libiberty/buildargv: handle input consisting of only white space Andrew Burgess
2024-05-26 15:08 ` Jeff Law
2024-06-11 10:39 ` Andrew Burgess
2024-06-11 10:41 ` Andrew Burgess
2024-04-27 9:48 ` [PATCHv2 0/2] Changes to libiberty buildargv Andrew Burgess
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=87a5po9dzd.fsf@redhat.com \
--to=aburgess@redhat.com \
--cc=gcc-patches@gcc.gnu.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).