From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 309BC3858413 for ; Tue, 2 Jan 2024 11:22:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 309BC3858413 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 309BC3858413 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704194558; cv=none; b=StpNw+/EIdgVIurzzMQKLd4SQHdFMwf2lRwGZFShr5VHVSzTLhYj+CYbTffjzfBTW5pH/AcztEo83cIFGdqXDGLZpIhEaQscGtAlIkKCDlUvPZ/cq0N6n9+t+oSMQM9mhwhmY7IHhlEUhOHvxjFe29Ds7pfMcPun5SZnK0i6TMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704194558; c=relaxed/simple; bh=42nHtdUgP3bcV4rM0tPWuWhEIsSquzeENl8LRueOcpA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=cr4FvmNcblJFlxvAqn1KtSCecAf8SToPQTObeZ1DjO3Dc/44aiN/6mmBm243bGHhQkrXsuV9dpGP05U5tek413QVx5fPgeg1111Eap/hThvfnQDWDv5e1RUsz0MNQ0yMij88F0AtkfOcBGi9NTNVMO2iI3KMLaf5+iJyhIstqv4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704194555; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kLWc5pxWxb4NdTLLheyYMybz/ZtzzPoKh5fjdDm+jGg=; b=LX2MwJzTB6fIQ9K60kkBOLGNyopGAty+UdpMPpeTlGMpyoVk8rayWlE95Obe653qOKtx0q PNwcm5+MaBA2Y0vLx3EgcQdDTW+MQ01BOQoBisbuz4dNXwxj3QJPH4lCNyb5LyG6K4W4Sf jq3bUVGntTY5TrAkYEBEMi+TOAilx1w= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-656-NT57dLaoNQqud5xM1hR9uw-1; Tue, 02 Jan 2024 06:22:34 -0500 X-MC-Unique: NT57dLaoNQqud5xM1hR9uw-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-336992b0f37so6001468f8f.0 for ; Tue, 02 Jan 2024 03:22:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704194552; x=1704799352; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kLWc5pxWxb4NdTLLheyYMybz/ZtzzPoKh5fjdDm+jGg=; b=gD0Sk8BQQpPR+2sT9J5UKcJR3k48iTQOZ6Ykmc+W81q++qclqbh42zZdKD5ci8DGsM JI2XqYYHvnSBxX3mUz49XmqCkJKkStxZiZB7pV5BjAPiTRe3DZC57syrrJQkm0bGvATk nyapEH16lrgt6Y1XAdxwunU9A5laRK/IBRvHV7z1S33k25Dz7N01H2uxIf0s4UzH38nC nJ+d4B/aUswI7BpBC3+6XT2DpZaSiNcdr9ZVTJAIXH3L3ERvCtQH8kQbqCv9aBXYTy3y v3rdl41YDzoCR5Bp6kIi9t4ZLH4acLv3J/+x2jweLTjAknqZdYpKBPR20Kq8VXKY0kY2 ipGQ== X-Gm-Message-State: AOJu0YzQ7LnB26mIT5HF+VwddiHAGduwXhQCGnTjZT3OFdBIBNBNR1V1 XZMqqs2JJB6OaZiak9GUt0s4TOR7W/Tfz1Tgv/o6QFQMQtWu0qvSES+hW7IV3vDC/IIMn84gtcF mkTRD7knrjA+L3ICjwVCRr+Ta5Kyw/kDIEXX3G3k2KN5Xb5SgVdef62IFnz8PPfu6ouU1dcnxAI jPxMWRo/z92A== X-Received: by 2002:a5d:4583:0:b0:336:9f70:a708 with SMTP id p3-20020a5d4583000000b003369f70a708mr7418381wrq.107.1704194552571; Tue, 02 Jan 2024 03:22:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IHR1NiFBnhcachBKBvNyNUPDrnmRVqRNFxoDSzDyKg6UYG8tP+d6VvIbkGiVs4Vyqy/7Fw8sA== X-Received: by 2002:a5d:4583:0:b0:336:9f70:a708 with SMTP id p3-20020a5d4583000000b003369f70a708mr7418375wrq.107.1704194552041; Tue, 02 Jan 2024 03:22:32 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id s10-20020adfdb0a000000b003367d48520dsm28311302wri.46.2024.01.02.03.22.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 03:22:31 -0800 (PST) From: Andrew Burgess To: gcc-patches@gcc.gnu.org Subject: Ping: Re: [PATCH] libiberty/buildargv: POSIX behaviour for backslash handling In-Reply-To: <24a8d878590403540bc9b579ba58805985a4d2f7.1701881419.git.aburgess@redhat.com> References: <24a8d878590403540bc9b579ba58805985a4d2f7.1701881419.git.aburgess@redhat.com> Date: Tue, 02 Jan 2024 11:22:30 +0000 Message-ID: <87a5po9dzd.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Ping! Thanks, Andrew Andrew Burgess 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