From unknown Tue Aug 19 14:23:02 2025 X-Loop: help-debbugs@gnu.org Subject: bug#30794: Cannot produce backslash through hexadecimal - sed (GNU sed) 4.2.2 Resent-From: 0xddaa <0xddaa@gmail.com> Original-Sender: "Debbugs-submit" Resent-CC: bug-sed@gnu.org Resent-Date: Tue, 13 Mar 2018 15:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 30794 X-GNU-PR-Package: sed X-GNU-PR-Keywords: To: 30794@debbugs.gnu.org X-Debbugs-Original-To: bug-sed@gnu.org Reply-To: 0xddaa@gmail.com Received: via spool by submit@debbugs.gnu.org id=B.152095475418095 (code B ref -1); Tue, 13 Mar 2018 15:26:01 +0000 Received: (at submit) by debbugs.gnu.org; 13 Mar 2018 15:25:54 +0000 Received: from localhost ([127.0.0.1]:59681 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1evloH-0004hm-M0 for submit@debbugs.gnu.org; Tue, 13 Mar 2018 11:25:53 -0400 Received: from eggs.gnu.org ([208.118.235.92]:58270) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1evglG-0002Tw-Be for submit@debbugs.gnu.org; Tue, 13 Mar 2018 06:02:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evglA-0002yd-4J for submit@debbugs.gnu.org; Tue, 13 Mar 2018 06:02:21 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=BAYES_40, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:37024) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evglA-0002yN-0Z for submit@debbugs.gnu.org; Tue, 13 Mar 2018 06:02:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49206) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evgl4-0004YU-17 for bug-sed@gnu.org; Tue, 13 Mar 2018 06:02:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evgky-0002ou-01 for bug-sed@gnu.org; Tue, 13 Mar 2018 06:02:14 -0400 Received: from mail-vk0-x236.google.com ([2607:f8b0:400c:c05::236]:40071) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1evgkx-0002oG-Qo for bug-sed@gnu.org; Tue, 13 Mar 2018 06:02:07 -0400 Received: by mail-vk0-x236.google.com with SMTP id n82so8104976vkf.7 for ; Tue, 13 Mar 2018 03:02:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:reply-to:sender:from:date:message-id:subject:to; bh=5hu4kFH8RgfsPuAjmt2i/+MkbGASWXHkAiVyZKAwLM4=; b=Y863Y+SS12jAONxHDUyacYNpi1hU7T5q0rWVFw/S1MtlIvKAYaDoSvpOfNDi7ZQZe3 95Mks+d9hd6jBCCe4eNNKuiwc7a9Shqwo8lt9c1urUycIqOHcFgb1ae0DUGhtpQ9sP38 o3YiRa0VdArpoi1PDI4KR0Yi36W2yG4uMyHISbgqhYQLKs7mlsVw5564h8rqkUIISGDI 2aFwgwoXo7me10HnxU/XfrzBydR7nTZzg0lmOi5flHgl+ba4oVewfAkAtb+qFcp15xbW I8QFM6vBHpklI6UG9rGpF+4I35rVEQFb1gcxZcPJ6c9wA6NX7KxZJSjxqypOgadi14K5 QAZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:sender:from:date :message-id:subject:to; bh=5hu4kFH8RgfsPuAjmt2i/+MkbGASWXHkAiVyZKAwLM4=; b=gZzMLbrz5o00rdKDV8g+modhaLwbHhnBo/jfyNm/rL21+w7pHNTkCaRqBaezDk1gam Y3bIakdGyah4fpcDaigl5ZGpjkont4AyED2+3D86g+dbcXR+W5kEAwMaWP+CrjvlvlMp 04yOzCaQbTSaOZPep8Q1UqzzZ5vNm3C9np+6n0sp6De7f48NLqz2n3bqucw/ur+kcysm h90M+Hej6WFr3IBYCOaNgelh/+8Uz26N9GHp+QbZu0GwiHzdJ0D9j85tTm0Zw71IvFa6 /XYsAyfL8LGZ0qDY2IvcdpL7VvBpPcfRezBZe0bEuRpT7014nToPSK0XlbXSVfQ8T80o 8efw== X-Gm-Message-State: AElRT7Glxa7uGNiWQDKMR7X8GVc1/N6z3Q3GLhx8LtePyghQcnKMSFFs QeR1iemKQ1/w1/OlzJi2G2vyzkqEQjA42nTKk1mSlg== X-Google-Smtp-Source: AG47ELvDitdjsrv3H3t2W4PIap/tM6sV6CCElSf3JUaNw+nFd/AZNOHoUIIEPzWeo2asIHefRks74t0lI0qmameGmwc= X-Received: by 10.31.213.2 with SMTP id m2mr14701vkg.98.1520935325841; Tue, 13 Mar 2018 03:02:05 -0700 (PDT) MIME-Version: 1.0 Received: by 10.176.66.131 with HTTP; Tue, 13 Mar 2018 03:02:05 -0700 (PDT) From: 0xddaa <0xddaa@gmail.com> Date: Tue, 13 Mar 2018 18:02:05 +0800 X-Google-Sender-Auth: HMzBKVAraTLJPbYNiY11WUeRP7I Message-ID: Content-Type: multipart/alternative; boundary="94eb2c07d8fed2c866056748592e" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -3.8 (---) X-Mailman-Approved-At: Tue, 13 Mar 2018 11:25:51 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.8 (---) --94eb2c07d8fed2c866056748592e Content-Type: text/plain; charset="UTF-8" Hi, I use sed to modify the field of size in file header for some binaries, and I found it will failed when the file size included *\x5c* (backslash) after converted into hexadecimal. There is the Proof-of-Concept: # echo z | sed 's/z/\x5c/' # \x5c == '\' \ # success # echo z | sed 's/z/\x5c\x61/' a # backslash is gone According the manual, *\xxx* should produce an ascii character. sed should not treat *\x5c* as an escape symbol. I also try the replacement with '&' and it's work fine: # echo z | sed 's/z/\x26\x61/' # \x26 == '&' &a // replace to & # echo z | sed 's/z/&\x61/' za // execute & feature I try to fix the problem and I hope it will be useful. Sorry for my bad English. https://github.com/0xddaa/sed/commit/723fa224c771ecd16913aea8117aa917877bbd38 Sincerely, ddaa --94eb2c07d8fed2c866056748592e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

I use sed to modify the field of size in file h= eader for some binaries, and I found it will failed when the file size incl= uded \x5c (backslash) after converted into hexadecimal.

There= is the Proof-of-Concept:

# echo z | sed 's/z/\x5c/' # = \x5c =3D=3D '\'
\ # success
# echo z | sed 's/z/\x= 5c\x61/'
a # backslash is gone

According the manual, <= b>\xxx should produce an ascii character. sed should not treat \x5c<= /b>=C2=A0as an escape symbol.

I also try the replacement with '&= amp;' and it's work fine:

# echo z | sed 's/z/\x26\= x61/' # \x26 =3D=3D '&'
&a // replace to &
<= div># echo z | sed 's/z/&\x61/'
za=C2=A0 // execute & feature

I try to fix the problem and I hope it will be useful. Sor= ry for my bad English.
https://github.com/0xddaa/sed/comm= it/723fa224c771ecd16913aea8117aa917877bbd38

Si= ncerely,
ddaa

--94eb2c07d8fed2c866056748592e-- From unknown Tue Aug 19 14:23:02 2025 X-Loop: help-debbugs@gnu.org Subject: bug#30794: Cannot produce backslash through hexadecimal - sed (GNU sed) 4.2.2 Resent-From: Assaf Gordon Original-Sender: "Debbugs-submit" Resent-CC: bug-sed@gnu.org Resent-Date: Wed, 14 Mar 2018 02:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30794 X-GNU-PR-Package: sed X-GNU-PR-Keywords: To: 0xddaa <0xddaa@gmail.com> Cc: 30794@debbugs.gnu.org Received: via spool by 30794-submit@debbugs.gnu.org id=B30794.152099554529567 (code B ref 30794); Wed, 14 Mar 2018 02:46:01 +0000 Received: (at 30794) by debbugs.gnu.org; 14 Mar 2018 02:45:45 +0000 Received: from localhost ([127.0.0.1]:60273 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1evwQD-0007gp-3Q for submit@debbugs.gnu.org; Tue, 13 Mar 2018 22:45:45 -0400 Received: from mail-pg0-f46.google.com ([74.125.83.46]:33726) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1evwQB-0007gb-11 for 30794@debbugs.gnu.org; Tue, 13 Mar 2018 22:45:43 -0400 Received: by mail-pg0-f46.google.com with SMTP id g12so782618pgs.0 for <30794@debbugs.gnu.org>; Tue, 13 Mar 2018 19:45:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=GV2GYzNyuzL4U6HUZFZnxOejdqgxHvPpjXAqiJGdx70=; b=OxvQ/Or0qvtDY0QJxhEImKLD1iZll7i9tFtX/TeyrGQ3Cey9Ot78HLFrwzMGady3Ar 3V/s8Uvi6rNzHxohg/E30xw7HrpM+Fc+OlDzjFaC57R6rO1hvIuJqFl6/PJbmtCqByYE YvBZQhZcAd8mAhsS2ExQp0I74kS4N401+5YQ/7xpV5C4+IqxhmbJqT0Ok3FUFbtXzA29 iCWZ2ZOhl811EW/OmvdRWxZjXJES5/XbPTE6EDVPXOPgSkZNpj9WRon83bSvvmseG80Z qV4q7n92hr4gsFL7pW6F56RiG3RZY4ieLJlixoikKiS+1SGf5iPP19HOE2u10jCoaIzz Tj5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=GV2GYzNyuzL4U6HUZFZnxOejdqgxHvPpjXAqiJGdx70=; b=Xhh2izAN9aJlwEB8D68zNouYw+nBrnj/zD1NFeKHwA7OZW/com0ggR7Iwu2nyIxE30 h18/PsXbDJB0mhH1WNZ7B9hztbgTa0JrkYZ64JrHyk8WaacjvEbshxftJ2JyfdlHFQzT x7pGgdTEzQ6L6P41CHdrpmuhlQLDHhWOAzWT9fMMODiBS6OQ3XvBEntmpBKs07pIGeed vBx73Z0gy3If1M80KXMvs0/XzUcvXAD8DzD60kqpry2ctuNEioo8vCb0x0OkMpGFOczs vv7eqbpXje59OMwc+9TKMeqlQu8ls2o0RtTi3MUjQUeR0uD8MCbP/EZx6NGMKXQr17WF rQZg== X-Gm-Message-State: AElRT7GX7k3VWfWbvaFjWwZUXhbRUuI72/cUGBRH0OUEmLJKyejojhjJ ztOsfHnUZGk/eBkndFH34r8= X-Google-Smtp-Source: AG47ELtSeytJ5UvOjdPc0em6NXu0ysxIQUrPq0VcuZ6ppZFzzxutXWz9tIzPsaB55kXeK0sxOyWlcw== X-Received: by 10.98.251.5 with SMTP id x5mr2752062pfm.18.1520995537211; Tue, 13 Mar 2018 19:45:37 -0700 (PDT) Received: from tomato (moose.housegordon.com. [184.68.105.38]) by smtp.gmail.com with ESMTPSA id e83sm2637900pfk.148.2018.03.13.19.45.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Mar 2018 19:45:35 -0700 (PDT) Date: Tue, 13 Mar 2018 20:45:32 -0600 From: Assaf Gordon Message-ID: <20180314024532.GA422@tomato> References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="UlVJffcvxoiEqYs2" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --UlVJffcvxoiEqYs2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello, On Tue, Mar 13, 2018 at 06:02:05PM +0800, 0xddaa wrote: > There is the Proof-of-Concept: > > # echo z | sed 's/z/\x5c/' # \x5c == '\' > \ # success > # echo z | sed 's/z/\x5c\x61/' > a # backslash is gone > > According the manual, *\xxx* should produce an ascii character. sed should > not treat *\x5c* as an escape symbol. Thank you for reporting this issue with such clear details and providing a bug fix - much appreciated! I expanded your fix by adding tests and news item, see attached patch. There is a small issue that this is a backwards incompatible change, and might break some exotic (bad) scripts. I'll wait for other opinions before pushing this. Jim, What do you think? regards, - assaf --UlVJffcvxoiEqYs2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-sed-treat-x5c-as-literal-backslash.patch" >From 9946f6d4177d65ac62b963af391c1c8ad022f7fa Mon Sep 17 00:00:00 2001 From: 0xddaa <0xddaa@gmail.com> Date: Tue, 13 Mar 2018 22:34:26 -0400 Subject: [PATCH] sed: treat '\x5c' as literal backslash Sed incorrectly treated '\x5c' (ASCII 92, backslash) as an escape character. Old behavior: $ echo z | sed -E 's/(z)/\x5c1/' # identical to 's/(z)/\1/' z New behavior: $ echo z | sed -E 's/(z)/\x5c1/' \1 Reported in https://bugs.gnu.org/30794. * NEWS: Mention bug fix. * sed/compile.c (normalize_text): Pass backslash as literal character. * testsuite/misc.pl: Add tests. --- NEWS | 10 ++++++++++ sed/compile.c | 2 +- testsuite/misc.pl | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index e762b2d..f9618e6 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,16 @@ GNU sed NEWS -*- outline -*- instead of the symlink target. [Bug present since at least sed-4.2] sed -i --follow-symlinks remains unchanged. + sed now treats the sequence '\x5c' (ASCII 92, backslash) as literal + backslash character, not as an escape prefix character. + [Bug present since at least sed-4.0.6] + Old behavior: + $ echo z | sed -E 's/(z)/\x5c1/' # identical to 's/(z)/\1/' + z + New behavior: + $ echo z | sed -E 's/(z)/\x5c1/' + \1 + * Noteworthy changes in release 4.4 (2017-02-03) [stable] diff --git a/sed/compile.c b/sed/compile.c index 26bd18a..25baf5e 100644 --- a/sed/compile.c +++ b/sed/compile.c @@ -1481,7 +1481,7 @@ convert: p = convert_number(&ch, p, bufend, base); /* for an ampersand in a replacement, pass the \ up one level */ - if (buftype == TEXT_REPLACEMENT && ch == '&') + if (buftype == TEXT_REPLACEMENT && (ch == '&' || ch == '\\')) *q++ = '\\'; *q++ = ch; continue; diff --git a/testsuite/misc.pl b/testsuite/misc.pl index 92838cb..3fa5b84 100644 --- a/testsuite/misc.pl +++ b/testsuite/misc.pl @@ -1190,6 +1190,13 @@ s,.*[^\/],, . "baaaacx\n"} ], + + # Four backslashes (2 pairs of "\\") to pass through two interpolations: + # once in Perl, then the shell command line argument. + # sed will see one backslash character in the s/// command. + ['bug30794_1', "s/z/\\\\x5cA/", {IN=>'z'}, {OUT => "\\A"}], + ['bug30794_2', "s/z/\\\\x5c/", {IN=>'z'}, {OUT => "\\"}], + ['bug30794_3', "s/z/\\\\x5c1/", {IN=>'z'}, {OUT => "\\1"}], ); my $save_temps = $ENV{SAVE_TEMPS}; -- 2.7.4 --UlVJffcvxoiEqYs2-- From unknown Tue Aug 19 14:23:02 2025 X-Loop: help-debbugs@gnu.org Subject: bug#30794: Cannot produce backslash through hexadecimal - sed (GNU sed) 4.2.2 Resent-From: 0xddaa <0xddaa@gmail.com> Original-Sender: "Debbugs-submit" Resent-CC: bug-sed@gnu.org Resent-Date: Wed, 14 Mar 2018 03:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30794 X-GNU-PR-Package: sed X-GNU-PR-Keywords: To: Assaf Gordon Cc: 0xddaa <0xddaa@gmail.com>, 30794@debbugs.gnu.org Reply-To: 0xddaa@gmail.com Received: via spool by 30794-submit@debbugs.gnu.org id=B30794.15209994393286 (code B ref 30794); Wed, 14 Mar 2018 03:51:02 +0000 Received: (at 30794) by debbugs.gnu.org; 14 Mar 2018 03:50:39 +0000 Received: from localhost ([127.0.0.1]:60289 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1evxR1-0000qw-KO for submit@debbugs.gnu.org; Tue, 13 Mar 2018 23:50:39 -0400 Received: from mail-vk0-f53.google.com ([209.85.213.53]:40826) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1evxQz-0000qi-Q5 for 30794@debbugs.gnu.org; Tue, 13 Mar 2018 23:50:38 -0400 Received: by mail-vk0-f53.google.com with SMTP id n82so1167889vkf.7 for <30794@debbugs.gnu.org>; Tue, 13 Mar 2018 20:50:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:reply-to:sender:in-reply-to:references:from:date :message-id:subject:to:cc; bh=7MiJNuZXM7EEHexjCZl35+XgduAG7dUa+uXLIRj6PZg=; b=kvWfY+eoapapCAg7oProt2NN9ViAZrfXCp+XOzXYkfU4YFnXhJQVDtMb6eumXH3tky vJPfOkM5QKbycR6vAels4ymjWDtMkDXav1zjR1eElIYbcM3NkkSUpNKbblJYAY17ao1J u77Sl9aRsvLrZM/GfBpQtvC0y8wQ+XqXpXuLdJUUSk16QaEkI+UEO+71E6Ay5U0KUMmG yPzvVN0tF+2LF0eS+J1B8MB533eqx0P0p5aMnM844zYXJLwkkS08UAbuTGxpXK0jqEZc WeokVZoCjmRtVKZKyIOC3kMLSFy3B7XOh/wCWTYvO+v8A1qRqFjtBNpqZ7QWm0gViAdf cUmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:sender:in-reply-to :references:from:date:message-id:subject:to:cc; bh=7MiJNuZXM7EEHexjCZl35+XgduAG7dUa+uXLIRj6PZg=; b=jCxSWOCRBtDvV07P5s8inp3EoigQLP2H66MeW3T0s0P3zjIL4oWYqqattw2RspO6bS 0xIAEIGAIJjCxl33eaZ3cQkyv8fIb6IK/cGy2bSqs9NXVyL/20c8q5HmpTeh07ZvdITf i3Utocx2c911qO09gWwhMvixE0ga9mA4toYagE13EDXowAV3lK7KFEsdMjW6xu/U7eC7 nh3p44gDGMM5p3EDDVEceq8IMgjpcnAJSTfXu3SiGv4e5dBSIZbydCcB9bU+NeQAG8lD QtqRBZFXaAeyjdm5WLzvvo+Bo6e1KtRUEWk09txP5MmZogWs2dOJFmDPRDUgDcLJzWnh 7xbA== X-Gm-Message-State: AElRT7F/pJtRdQ2oVv+laceEsHTcX7TrDPhqQlLyXHwyGE10pTYG1LdJ YX0Ocd//OFJf0uDozIY/dPYPJylIso8JErlPRsc= X-Google-Smtp-Source: AG47ELsZOaabkUQyYQXTKB3eK3O8GY1Q0jSHOeKCNmOMIGhq4PU0le4KHJ+n3hJHKNFHM5Zal7Flj6QIlsOpmVp3tqg= X-Received: by 10.31.73.129 with SMTP id w123mr2419942vka.102.1520999432003; Tue, 13 Mar 2018 20:50:32 -0700 (PDT) MIME-Version: 1.0 Received: by 10.176.66.131 with HTTP; Tue, 13 Mar 2018 20:50:31 -0700 (PDT) In-Reply-To: <20180314024532.GA422@tomato> References: <20180314024532.GA422@tomato> From: 0xddaa <0xddaa@gmail.com> Date: Wed, 14 Mar 2018 11:50:31 +0800 X-Google-Sender-Auth: ST7OAwXPsk5fLVcZgF2fA9mVI14 Message-ID: Content-Type: multipart/alternative; boundary="001a114d66f6d923e30567574638" X-Spam-Score: 0.2 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.2 (/) --001a114d66f6d923e30567574638 Content-Type: text/plain; charset="UTF-8" I am glad that my report is helpful. Thanks for your praise. :) 2018-03-14 10:45 GMT+08:00 Assaf Gordon : > Hello, > > On Tue, Mar 13, 2018 at 06:02:05PM +0800, 0xddaa wrote: > > There is the Proof-of-Concept: > > > > # echo z | sed 's/z/\x5c/' # \x5c == '\' > > \ # success > > # echo z | sed 's/z/\x5c\x61/' > > a # backslash is gone > > > > According the manual, *\xxx* should produce an ascii character. sed > should > > not treat *\x5c* as an escape symbol. > > Thank you for reporting this issue with such clear details > and providing a bug fix - much appreciated! > > I expanded your fix by adding tests and news item, see attached patch. > > There is a small issue that this is a backwards incompatible change, > and might break some exotic (bad) scripts. > > I'll wait for other opinions before pushing this. > > Jim, > What do you think? > > regards, > - assaf > --001a114d66f6d923e30567574638 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I am glad that my report is helpful.
Thanks for your pr= aise. :)

201= 8-03-14 10:45 GMT+08:00 Assaf Gordon <assafgordon@gmail.com>:
Hello,

On Tue, Mar 13, 2018 at 06:02:05PM +0800, 0xddaa wrote:
> There is the Proof-of-Concept:
>
> # echo z | sed 's/z/\x5c/' # \x5c =3D=3D '\'
> \ # success
> # echo z | sed 's/z/\x5c\x61/'
> a # backslash is gone
>
> According the manual, *\xxx* should produce an ascii character. sed sh= ould
> not treat *\x5c* as an escape symbol.

Thank you for reporting this issue with such clear details
and providing a bug fix - much appreciated!

I expanded your fix by adding tests and news item, see attached patch.

There is a small issue that this is a backwards incompatible change,
and might break some exotic (bad) scripts.

I'll wait for other opinions before pushing this.

Jim,
What do you think?

regards,
=C2=A0- assaf

--001a114d66f6d923e30567574638-- From unknown Tue Aug 19 14:23:02 2025 X-Loop: help-debbugs@gnu.org Subject: bug#30794: Cannot produce backslash through hexadecimal - sed (GNU sed) 4.2.2 Resent-From: Jim Meyering Original-Sender: "Debbugs-submit" Resent-CC: bug-sed@gnu.org Resent-Date: Wed, 14 Mar 2018 04:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30794 X-GNU-PR-Package: sed X-GNU-PR-Keywords: To: Assaf Gordon Cc: 0xddaa <0xddaa@gmail.com>, 30794@debbugs.gnu.org Received: via spool by 30794-submit@debbugs.gnu.org id=B30794.15210027848851 (code B ref 30794); Wed, 14 Mar 2018 04:47:01 +0000 Received: (at 30794) by debbugs.gnu.org; 14 Mar 2018 04:46:24 +0000 Received: from localhost ([127.0.0.1]:60296 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1evyIx-0002Ih-Tp for submit@debbugs.gnu.org; Wed, 14 Mar 2018 00:46:24 -0400 Received: from mail-qt0-f179.google.com ([209.85.216.179]:41388) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1evyIw-0002IR-GC for 30794@debbugs.gnu.org; Wed, 14 Mar 2018 00:46:22 -0400 Received: by mail-qt0-f179.google.com with SMTP id j4so2144837qth.8 for <30794@debbugs.gnu.org>; Tue, 13 Mar 2018 21:46:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=eZ5f67mHy1M8hII63LuFUDwrRg5IF4pax4bZ7u6YhzE=; b=HNMGdxbd6KULFpC9QLyv0k1iBc7LZo1cWe3SuIX398WKgC8XAOlaTDJa4lrSJRpcM/ 1IdthisRNtW0O29antZu+HrvOuZBRbV63YZhHHvhNdd0Z8rG2lyZ1CfM5QzHPtP6Llz6 t/5B3u3ieSTQABhsF/nFfeoj7ThXnbKdXQu2l3cu7ZUKwnMXrXbISiTW2aQfGXIEnxP+ 4pCWObJXsJ7eo0AzkPHqg35aDzPzJg51+9Rq0t5hGYbXiU3Q7J2t7ZzYYkr5rMxmiqIU tQUho85xOqFAFjXHlgPE10H1iEGqFWe5urrcL7CCiZpqTxreqU4X/MHJuIoQqhwGlMCm hhjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=eZ5f67mHy1M8hII63LuFUDwrRg5IF4pax4bZ7u6YhzE=; b=O/SIFBtyT9D1Wt5KSRKnfCxCO8tVM0xNlvoEm7YaGVWa/SUeZuSmiz4si1ejvzDL19 qYnbVroP2hkUlr2GSNeYxwjpJKuNuUDuwYamMClpPvi3ON6eb2RPXJ3JAYOKSzSq0q4W 8Ujkk/o4biFDHWA6+J6nX2NjS7zjWfswo6v2JeWZaQ7cTtRDRU9Lq0Ei/rXx9807m8I3 bxI9fF2wva9vo/iTz5CGrL02q+8rz5xQpe7Zl8obVI0fLjFIP5byN0R8pngDgVeDdrfV 43QyfMQoZ98rwCFAPpdlllVRTFpFM/914ZNKo4cBOnbX6HbAMZwyVUzYKIBv41pt0oti VZNg== X-Gm-Message-State: AElRT7ENtxNKHJWPSLtB1FhjjMS4Daxlcr5j0gAR8CRArFD8HPn4aSp7 HBoFF3+p8PrbqDIduDHB/AMl3eXITTGXhjjiaF8= X-Google-Smtp-Source: AG47ELuseo7+QyoCV7CZxPfp4Fz1uk9lK5jsAeMg3/jNmtkZxR6eRz+D/1/GWSZou26OXrRycR7fpGiF7DkG4fbmC/c= X-Received: by 10.237.47.165 with SMTP id m34mr5176664qtd.178.1521002776640; Tue, 13 Mar 2018 21:46:16 -0700 (PDT) MIME-Version: 1.0 Received: by 10.55.77.23 with HTTP; Tue, 13 Mar 2018 21:45:55 -0700 (PDT) In-Reply-To: <20180314024532.GA422@tomato> References: <20180314024532.GA422@tomato> From: Jim Meyering Date: Tue, 13 Mar 2018 21:45:55 -0700 X-Google-Sender-Auth: uRNIacXO85h9UymSL1kR1RsN5sQ Message-ID: Content-Type: text/plain; charset="UTF-8" X-Spam-Score: -0.2 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.2 (/) On Tue, Mar 13, 2018 at 7:45 PM, Assaf Gordon wrote: ... > Thank you for reporting this issue with such clear details > and providing a bug fix - much appreciated! > > I expanded your fix by adding tests and news item, see attached patch. > > There is a small issue that this is a backwards incompatible change, > and might break some exotic (bad) scripts. > > I'll wait for other opinions before pushing this. > > Jim, > What do you think? Thanks for the fine work from both of you. Assaf, I think it's fair to extend the bound in the NEWS to say this: [Bug present since the beginning] To conclude that, I ran the following on a modern system for which I have built many old sed binaries. Note that I dropped the "-E" and instead use a BRE, since -E and -r were not present in the earlier releases. $ for i in $(env ls -dv /p/p/sed-*); do printf '%-14s: ' $i; echo z | $i/bin/sed 's/\(z\)/\x5c1/'; done|sed s/.....// s: sed-1.18 : x5c1 sed-2.05 : x5c1 sed-3.01 : x5c1 sed-3.02 : x5c1 sed-4.0a : z sed-4.0b : z sed-4.0c : z sed-4.0d : z sed-4.0e : z sed-4.0.6: z sed-4.0.7: z sed-4.0.8: z sed-4.0.9: z sed-4.1 : z sed-4.1c : z sed-4.1d : z sed-4.1e : z sed-4.1f : z sed-4.1.1: z sed-4.1.2: z sed-4.1.3: z sed-4.1.4: z sed-4.1.5: z sed-4.2 : z sed-4.2.1: z sed-4.2.2: z sed-4.3 : z sed-4.4 : z From unknown Tue Aug 19 14:23:02 2025 X-Loop: help-debbugs@gnu.org Subject: bug#30794: Cannot produce backslash through hexadecimal - sed (GNU sed) 4.2.2 Resent-From: Assaf Gordon Original-Sender: "Debbugs-submit" Resent-CC: bug-sed@gnu.org Resent-Date: Wed, 14 Mar 2018 22:35:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30794 X-GNU-PR-Package: sed X-GNU-PR-Keywords: To: Jim Meyering Cc: 0xddaa <0xddaa@gmail.com>, 30794@debbugs.gnu.org Received: via spool by 30794-submit@debbugs.gnu.org id=B30794.152106686927499 (code B ref 30794); Wed, 14 Mar 2018 22:35:01 +0000 Received: (at 30794) by debbugs.gnu.org; 14 Mar 2018 22:34:29 +0000 Received: from localhost ([127.0.0.1]:33738 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ewEya-00079T-Tq for submit@debbugs.gnu.org; Wed, 14 Mar 2018 18:34:29 -0400 Received: from mail-pg0-f52.google.com ([74.125.83.52]:35823) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ewEya-00079F-2i for 30794@debbugs.gnu.org; Wed, 14 Mar 2018 18:34:28 -0400 Received: by mail-pg0-f52.google.com with SMTP id d1so2004121pgv.2 for <30794@debbugs.gnu.org>; Wed, 14 Mar 2018 15:34:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=sqi6I8rzzzQlEw/fuOnMGCnRggDnCeHTX7IqRSmsZTU=; b=SAa+bB9l+i9Q/w1dAAH0lT6DcX55ZlCk9HNcOvy5GEoeqLdHXNwBmw0ln2F4i9eae3 2PNJ9ShOypHgbsbV6q0ZxeNrkdtIz1IsCLDM+SEIbMm/rdDdx+vknBZi8gpQ0JONYUvQ GZ4MmEngI5HYpVYka+nnAKgssEVrCG1SwEy+IGam7lnwsZNBKRU9ksJ2Ju3XD7wFVmyO a20aJ3IiIJLyYYFgdrJpWYH7kMtH0x5Tx9tC/skaxG7q01VgRE8TrhOCKmkhFgghnnvL UDt3kSCKbNTdzUJb/7/LI6adz1Z2Tut8ftE8JLMOFi7/JBvYUY0T8Zzk2z4KhzZ+/YnO 5GFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=sqi6I8rzzzQlEw/fuOnMGCnRggDnCeHTX7IqRSmsZTU=; b=f5P5NuBt0tXtou/mawVQ6JdRpI2cKeUE/GoiuZ8et9qYOjwy5QIeajccJ3B7NQZoeH pPvfkDMglmBdMyCNFlzSBc0wjYmJcERALJZur9VJjYvK15pyEOMKrM0AjkwnsmvWjexq E4OP0f54si6uGFCiWwO4oTqEQe4zB1CRmgTbvs1rZMhDxWE8mVlm0/mPMF4Q+dxs0fh0 6UqVmFnoFoZO76I4zfsv2YVyXylM4ZGYK1UE0/t4rocYyXv79LZdlCci1tiLgqzDdHal ChwHnzUgxbPDfwoUa8nb9Ixy53ngn5ozJVnyLEsnAgZDrNhPLSloduH/Ja951VqkNI1F J4aQ== X-Gm-Message-State: AElRT7HDREj8bT+bqGUMR0SPufJb8xb2/KIFZMbmzQutG8d99k9yXBrP qFPB60p0Oph6ywPycr/aAws= X-Google-Smtp-Source: AG47ELv/zRyOWvCXOFLQQbF/ZkAxRQ0ZaB6ZxqyWX1/XwElaQHC2rL1KAuecYHRjsnjULMZXGE/WdA== X-Received: by 10.98.108.2 with SMTP id h2mr5708861pfc.43.1521066862097; Wed, 14 Mar 2018 15:34:22 -0700 (PDT) Received: from tomato (moose.housegordon.com. [184.68.105.38]) by smtp.gmail.com with ESMTPSA id n67sm7346283pfh.150.2018.03.14.15.34.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 15:34:20 -0700 (PDT) Date: Wed, 14 Mar 2018 16:34:18 -0600 From: Assaf Gordon Message-ID: <20180314223418.GB422@tomato> References: <20180314024532.GA422@tomato> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Hello Jim, On Tue, Mar 13, 2018 at 09:45:55PM -0700, Jim Meyering wrote: > On Tue, Mar 13, 2018 at 7:45 PM, Assaf Gordon wrote: > ... > > I expanded your fix by adding tests and news item, see attached patch. > > > Thanks for the fine work from both of you. > Assaf, I think it's fair to extend the bound in the NEWS to say this: > > [Bug present since the beginning] > > To conclude that, I ran the following on a modern system for which I > have built many old sed binaries. > [...] > $ for i in $(env ls -dv /p/p/sed-*); do printf '%-14s: ' $i; echo z | > $i/bin/sed 's/\(z\)/\x5c1/'; done|sed s/.....// s: > sed-1.18 : x5c1 > sed-2.05 : x5c1 > sed-3.01 : x5c1 > sed-3.02 : x5c1 > [...] Sorry for bike-shedding, but wouldn't you say that if "\x5c1" is printed it means that older seds do not understand hex characters, and simply treated "\x" as "x" ? -assaf From unknown Tue Aug 19 14:23:02 2025 X-Loop: help-debbugs@gnu.org Subject: bug#30794: Cannot produce backslash through hexadecimal - sed (GNU sed) 4.2.2 Resent-From: Assaf Gordon Original-Sender: "Debbugs-submit" Resent-CC: bug-sed@gnu.org Resent-Date: Wed, 14 Mar 2018 22:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30794 X-GNU-PR-Package: sed X-GNU-PR-Keywords: To: Jim Meyering Cc: 0xddaa <0xddaa@gmail.com>, 30794@debbugs.gnu.org Received: via spool by 30794-submit@debbugs.gnu.org id=B30794.152106740528342 (code B ref 30794); Wed, 14 Mar 2018 22:44:02 +0000 Received: (at 30794) by debbugs.gnu.org; 14 Mar 2018 22:43:25 +0000 Received: from localhost ([127.0.0.1]:33742 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ewF7E-0007N4-QK for submit@debbugs.gnu.org; Wed, 14 Mar 2018 18:43:25 -0400 Received: from mail-pl0-f49.google.com ([209.85.160.49]:36370) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ewF7D-0007Mq-CL for 30794@debbugs.gnu.org; Wed, 14 Mar 2018 18:43:24 -0400 Received: by mail-pl0-f49.google.com with SMTP id 61-v6so2561462plf.3 for <30794@debbugs.gnu.org>; Wed, 14 Mar 2018 15:43:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=+JVAsOfgSwij04T++p2y0d/9ZKIeSKhFLoXNAWyn+Qs=; b=npXk44kErmnhLLklFN//QafZrrdkpvsPrdEFtUiFVGg7EMRbcR0XZOVzOdEA26Qhzx 9qMjW8X4Wp4mMLwoOAeJBDSBUqGiubVO5jd5u1bt8ikdGz5oONg+b1Uznt5OH+OFGrgf ZFcnzl1xpi6rv/PVuI+vkXNXwhApp6rHCpUiRl+2cIdC6ZlG4dGClev2dN8ObS06M0ld nM0zz1iuhZ0OzmeLmmdo8PgvsEcYz/9Llu7Y22eNn50mNA4+O51udeUJVq1Gl/OKYBJE Ca9TPpbvx63Er5YGaF3/Ul2k/1aiXsuHGkDbh6Wn0WzODiTh5d+3telEntMZta+1LRbc W5rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=+JVAsOfgSwij04T++p2y0d/9ZKIeSKhFLoXNAWyn+Qs=; b=ZMGac6SNZXeat9jjyWC1Lx3FmtQBJytoX0r4MBlBpO8roPSTdrF7oesZU1QNAQQioQ 85Fu0aZk4IHw0DngyJwPLgnOfawxTqzTmnRTXOSSMX6GMD2CxJ53SZAVu7vZLBMYJ/NN GxFTZBlaDmJUil47Qn+2dUAsbW3WqtMvmucCb7sNgvuCPqm+rINbQM8vm3n0+ffEfneV b9jXN3/j+vWsvjriVoTqNQPX+b1NYBPvOfqjQWf7jwDQ6TYByq6L/udQpszZmTzJnzwi Xsb8zZbV3vf05fUblBUh8CbzOlovWLqpGNCfps3p882f2p7S6Y0BsTxlQBPXWQhAj/BN 8dHg== X-Gm-Message-State: AElRT7F7CDFjawpBctrbg2nqqgDvoigZWQN0kqo4iY+YGwozfNSVY34B FK5S+aNl46L5h4FimwLuD+Q= X-Google-Smtp-Source: AG47ELvH3e6J//LQB0BUPZMKmtunEHmBR4Fa6+TRv16KsjCI3qXhRHVf5XZy9kM0d7LkS06E1l5Oqg== X-Received: by 2002:a17:902:a614:: with SMTP id u20-v6mr5581171plq.249.1521067397555; Wed, 14 Mar 2018 15:43:17 -0700 (PDT) Received: from tomato (moose.housegordon.com. [184.68.105.38]) by smtp.gmail.com with ESMTPSA id c62sm7587655pfk.127.2018.03.14.15.43.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 15:43:15 -0700 (PDT) Date: Wed, 14 Mar 2018 16:43:11 -0600 From: Assaf Gordon Message-ID: <20180314224311.GC422@tomato> References: <20180314024532.GA422@tomato> <20180314223418.GB422@tomato> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="KFztAG8eRSV9hGtP" Content-Disposition: inline In-Reply-To: <20180314223418.GB422@tomato> User-Agent: Mutt/1.5.24 (2015-08-30) X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --KFztAG8eRSV9hGtP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Replying to myself: On Wed, Mar 14, 2018 at 04:34:18PM -0600, Assaf Gordon wrote: > > [...] > > sed-1.18 : x5c1 > > sed-2.05 : x5c1 > > sed-3.01 : x5c1 > > sed-3.02 : x5c1 > > [...] I checked the NEWS file, and found that backslash sequences (e.g. \n \t \xNN \dNNN \oNNN) were added in version 3.02.80 (which I don't think is common and we don't have the source code). I changed the NEWS accordingly (attached updated patch). OK to push? thanks, - assaf --KFztAG8eRSV9hGtP Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-sed-treat-x5c-as-literal-backslash.patch" >From b5f5236a4b3a2d6c2f89fb99d614486a65a40a24 Mon Sep 17 00:00:00 2001 From: 0xddaa <0xddaa@gmail.com> Date: Tue, 13 Mar 2018 22:34:26 -0400 Subject: [PATCH] sed: treat '\x5c' as literal backslash Sed incorrectly treated '\x5c' (ASCII 92, backslash) as an escape character. Old behavior: $ echo z | sed -E 's/(z)/\x5c1/' # identical to 's/(z)/\1/' z New behavior: $ echo z | sed -E 's/(z)/\x5c1/' \1 Reported in https://bugs.gnu.org/30794. * NEWS: Mention bug fix. * sed/compile.c (normalize_text): Pass backslash as literal character. * testsuite/misc.pl: Add tests. --- NEWS | 10 ++++++++++ sed/compile.c | 2 +- testsuite/misc.pl | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index e762b2d..e218a72 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,16 @@ GNU sed NEWS -*- outline -*- instead of the symlink target. [Bug present since at least sed-4.2] sed -i --follow-symlinks remains unchanged. + sed now treats the sequence '\x5c' (ASCII 92, backslash) as literal + backslash character, not as an escape prefix character. + [Bug present since sed-3.02.80] + Old behavior: + $ echo z | sed -E 's/(z)/\x5c1/' # identical to 's/(z)/\1/' + z + New behavior: + $ echo z | sed -E 's/(z)/\x5c1/' + \1 + * Noteworthy changes in release 4.4 (2017-02-03) [stable] diff --git a/sed/compile.c b/sed/compile.c index 26bd18a..25baf5e 100644 --- a/sed/compile.c +++ b/sed/compile.c @@ -1481,7 +1481,7 @@ convert: p = convert_number(&ch, p, bufend, base); /* for an ampersand in a replacement, pass the \ up one level */ - if (buftype == TEXT_REPLACEMENT && ch == '&') + if (buftype == TEXT_REPLACEMENT && (ch == '&' || ch == '\\')) *q++ = '\\'; *q++ = ch; continue; diff --git a/testsuite/misc.pl b/testsuite/misc.pl index 92838cb..3fa5b84 100644 --- a/testsuite/misc.pl +++ b/testsuite/misc.pl @@ -1190,6 +1190,13 @@ s,.*[^\/],, . "baaaacx\n"} ], + + # Four backslashes (2 pairs of "\\") to pass through two interpolations: + # once in Perl, then the shell command line argument. + # sed will see one backslash character in the s/// command. + ['bug30794_1', "s/z/\\\\x5cA/", {IN=>'z'}, {OUT => "\\A"}], + ['bug30794_2', "s/z/\\\\x5c/", {IN=>'z'}, {OUT => "\\"}], + ['bug30794_3', "s/z/\\\\x5c1/", {IN=>'z'}, {OUT => "\\1"}], ); my $save_temps = $ENV{SAVE_TEMPS}; -- 2.7.4 --KFztAG8eRSV9hGtP-- From unknown Tue Aug 19 14:23:02 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: 0xddaa@gmail.com Subject: bug#30794: closed (Re: bug#30794: Cannot produce backslash through hexadecimal - sed (GNU sed) 4.2.2) Message-ID: References: X-Gnu-PR-Message: they-closed 30794 X-Gnu-PR-Package: sed Reply-To: 30794@debbugs.gnu.org Date: Thu, 15 Mar 2018 00:20:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1521073202-5562-1" This is a multi-part message in MIME format... ------------=_1521073202-5562-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #30794: Cannot produce backslash through hexadecimal - sed (GNU sed) 4.2.2 which was filed against the sed package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 30794@debbugs.gnu.org. --=20 30794: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D30794 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1521073202-5562-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 30794-done) by debbugs.gnu.org; 15 Mar 2018 00:19:11 +0000 Received: from localhost ([127.0.0.1]:33788 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ewGbu-0001QP-UL for submit@debbugs.gnu.org; Wed, 14 Mar 2018 20:19:11 -0400 Received: from mail-qk0-f177.google.com ([209.85.220.177]:41823) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ewGbt-0001QA-W5 for 30794-done@debbugs.gnu.org; Wed, 14 Mar 2018 20:19:10 -0400 Received: by mail-qk0-f177.google.com with SMTP id s78so5517469qkl.8 for <30794-done@debbugs.gnu.org>; Wed, 14 Mar 2018 17:19:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=5uLDYrTdOJnv/azDiWsOkhB2lekFe79rioHH67cX/cc=; b=cm9NiKz7ucJQ8UaR+EPETs/sYTVfCd6fpNfDEvXgz+wwEVrRR5LczirRW4Jg7Jjt3m IEK9gdGWf9eQqf4TylnIoD+Ru4uU47WbKkufYDRz5TSHKElSTPfXxBWdY6lIYjGqZW68 aSmvyRJf8PzgT0Z2d2Zo7vem2ELoVh5590iJVzHnVtHLeYucMV2bYKDCSo063K0vXTBs JXynsyciVRYYgXLRfh18ew+ZkYgzRrq41hE+BTSWkHzeHg9/Squtdt8BdmrVkXRalvhI 0qSmDAGPZYok7Lid4kP5+aLAf+oCPMBjIDFJIE44yzyw97fGuPuFikpfE7+P6c5QBVh/ 8dGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=5uLDYrTdOJnv/azDiWsOkhB2lekFe79rioHH67cX/cc=; b=GEEzcmUyE9B9fRMvD8fTvxHpKLCLL8o1JWDL8RvLXRUhalQqHgJrd5qJRUT8jMirEp D3lVStiiI6wnsZRG5YzCbHjyatcTPJ/IhF1/MnN8GzXGMEbbKXTPAmn0j67KmUjpjODu +aDOZ0+owIl+QiqBM4LJRTjkPIlj4s+5ff+KuTGXB0XnY1c6179k26x8lJQzrG2NIS1G 9YhY1y9vPxp+E6qQmu3utZgtJ3JAjUFaDJ7xg373s6j8Q9Ut1Zem9xTecjxp5PUmKBvq 2yJfVer/cW9g/DWviGWo2vL0vPeg3uE32isDS79OGLoc5DwsVzEho5mf/LkfIwJKAptL Zv0g== X-Gm-Message-State: AElRT7G7qyMDmIjw5Xm+lu/Es3BYnwrukvzsysfOcBBqfemRea2zwBJ0 TTY5nzi9HYGAQR2nn1nx5iYQWbTOpfTC4h+wh5k= X-Google-Smtp-Source: AG47ELvXGSlbFaZkKRldVJW4mJ0go4C3Ibeks5hZ62gaDCjpqAaaj9T2imvH9ZphTvA+qgFV4aXaBS4f2iTOyLbu0x8= X-Received: by 10.55.177.2 with SMTP id a2mr9496816qkf.352.1521073144430; Wed, 14 Mar 2018 17:19:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.55.77.23 with HTTP; Wed, 14 Mar 2018 17:18:43 -0700 (PDT) In-Reply-To: <20180314224311.GC422@tomato> References: <20180314024532.GA422@tomato> <20180314223418.GB422@tomato> <20180314224311.GC422@tomato> From: Jim Meyering Date: Wed, 14 Mar 2018 17:18:43 -0700 X-Google-Sender-Auth: 5e2dbjnc4yBiNKvbAnJqRMIxUKw Message-ID: Subject: Re: bug#30794: Cannot produce backslash through hexadecimal - sed (GNU sed) 4.2.2 To: Assaf Gordon Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 30794-done Cc: 0xddaa <0xddaa@gmail.com>, 30794-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) On Wed, Mar 14, 2018 at 3:43 PM, Assaf Gordon wrote: > Replying to myself: > > On Wed, Mar 14, 2018 at 04:34:18PM -0600, Assaf Gordon wrote: >> > [...] >> > sed-1.18 : x5c1 >> > sed-2.05 : x5c1 >> > sed-3.01 : x5c1 >> > sed-3.02 : x5c1 >> > [...] > > I checked the NEWS file, > and found that backslash sequences (e.g. \n \t \xNN \dNNN \oNNN) > were added in version 3.02.80 (which I don't think is common and > we don't have the source code). > > I changed the NEWS accordingly (attached updated patch). > > OK to push? Sure. Re the "bug present since..." issue, my intent was to convey that \x5c never worked the way we now consider correct. ------------=_1521073202-5562-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 13 Mar 2018 15:25:54 +0000 Received: from localhost ([127.0.0.1]:59681 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1evloH-0004hm-M0 for submit@debbugs.gnu.org; Tue, 13 Mar 2018 11:25:53 -0400 Received: from eggs.gnu.org ([208.118.235.92]:58270) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1evglG-0002Tw-Be for submit@debbugs.gnu.org; Tue, 13 Mar 2018 06:02:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evglA-0002yd-4J for submit@debbugs.gnu.org; Tue, 13 Mar 2018 06:02:21 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=BAYES_40, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:37024) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evglA-0002yN-0Z for submit@debbugs.gnu.org; Tue, 13 Mar 2018 06:02:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49206) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evgl4-0004YU-17 for bug-sed@gnu.org; Tue, 13 Mar 2018 06:02:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evgky-0002ou-01 for bug-sed@gnu.org; Tue, 13 Mar 2018 06:02:14 -0400 Received: from mail-vk0-x236.google.com ([2607:f8b0:400c:c05::236]:40071) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1evgkx-0002oG-Qo for bug-sed@gnu.org; Tue, 13 Mar 2018 06:02:07 -0400 Received: by mail-vk0-x236.google.com with SMTP id n82so8104976vkf.7 for ; Tue, 13 Mar 2018 03:02:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:reply-to:sender:from:date:message-id:subject:to; bh=5hu4kFH8RgfsPuAjmt2i/+MkbGASWXHkAiVyZKAwLM4=; b=Y863Y+SS12jAONxHDUyacYNpi1hU7T5q0rWVFw/S1MtlIvKAYaDoSvpOfNDi7ZQZe3 95Mks+d9hd6jBCCe4eNNKuiwc7a9Shqwo8lt9c1urUycIqOHcFgb1ae0DUGhtpQ9sP38 o3YiRa0VdArpoi1PDI4KR0Yi36W2yG4uMyHISbgqhYQLKs7mlsVw5564h8rqkUIISGDI 2aFwgwoXo7me10HnxU/XfrzBydR7nTZzg0lmOi5flHgl+ba4oVewfAkAtb+qFcp15xbW I8QFM6vBHpklI6UG9rGpF+4I35rVEQFb1gcxZcPJ6c9wA6NX7KxZJSjxqypOgadi14K5 QAZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:sender:from:date :message-id:subject:to; bh=5hu4kFH8RgfsPuAjmt2i/+MkbGASWXHkAiVyZKAwLM4=; b=gZzMLbrz5o00rdKDV8g+modhaLwbHhnBo/jfyNm/rL21+w7pHNTkCaRqBaezDk1gam Y3bIakdGyah4fpcDaigl5ZGpjkont4AyED2+3D86g+dbcXR+W5kEAwMaWP+CrjvlvlMp 04yOzCaQbTSaOZPep8Q1UqzzZ5vNm3C9np+6n0sp6De7f48NLqz2n3bqucw/ur+kcysm h90M+Hej6WFr3IBYCOaNgelh/+8Uz26N9GHp+QbZu0GwiHzdJ0D9j85tTm0Zw71IvFa6 /XYsAyfL8LGZ0qDY2IvcdpL7VvBpPcfRezBZe0bEuRpT7014nToPSK0XlbXSVfQ8T80o 8efw== X-Gm-Message-State: AElRT7Glxa7uGNiWQDKMR7X8GVc1/N6z3Q3GLhx8LtePyghQcnKMSFFs QeR1iemKQ1/w1/OlzJi2G2vyzkqEQjA42nTKk1mSlg== X-Google-Smtp-Source: AG47ELvDitdjsrv3H3t2W4PIap/tM6sV6CCElSf3JUaNw+nFd/AZNOHoUIIEPzWeo2asIHefRks74t0lI0qmameGmwc= X-Received: by 10.31.213.2 with SMTP id m2mr14701vkg.98.1520935325841; Tue, 13 Mar 2018 03:02:05 -0700 (PDT) MIME-Version: 1.0 Received: by 10.176.66.131 with HTTP; Tue, 13 Mar 2018 03:02:05 -0700 (PDT) From: 0xddaa <0xddaa@gmail.com> Date: Tue, 13 Mar 2018 18:02:05 +0800 X-Google-Sender-Auth: HMzBKVAraTLJPbYNiY11WUeRP7I Message-ID: Subject: Cannot produce backslash through hexadecimal - sed (GNU sed) 4.2.2 To: bug-sed@gnu.org Content-Type: multipart/alternative; boundary="94eb2c07d8fed2c866056748592e" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -3.8 (---) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Tue, 13 Mar 2018 11:25:51 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: 0xddaa@gmail.com Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.8 (---) --94eb2c07d8fed2c866056748592e Content-Type: text/plain; charset="UTF-8" Hi, I use sed to modify the field of size in file header for some binaries, and I found it will failed when the file size included *\x5c* (backslash) after converted into hexadecimal. There is the Proof-of-Concept: # echo z | sed 's/z/\x5c/' # \x5c == '\' \ # success # echo z | sed 's/z/\x5c\x61/' a # backslash is gone According the manual, *\xxx* should produce an ascii character. sed should not treat *\x5c* as an escape symbol. I also try the replacement with '&' and it's work fine: # echo z | sed 's/z/\x26\x61/' # \x26 == '&' &a // replace to & # echo z | sed 's/z/&\x61/' za // execute & feature I try to fix the problem and I hope it will be useful. Sorry for my bad English. https://github.com/0xddaa/sed/commit/723fa224c771ecd16913aea8117aa917877bbd38 Sincerely, ddaa --94eb2c07d8fed2c866056748592e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

I use sed to modify the field of size in file h= eader for some binaries, and I found it will failed when the file size incl= uded \x5c (backslash) after converted into hexadecimal.

There= is the Proof-of-Concept:

# echo z | sed 's/z/\x5c/' # = \x5c =3D=3D '\'
\ # success
# echo z | sed 's/z/\x= 5c\x61/'
a # backslash is gone

According the manual, <= b>\xxx
should produce an ascii character. sed should not treat \x5c<= /b>=C2=A0as an escape symbol.

I also try the replacement with '&= amp;' and it's work fine:

# echo z | sed 's/z/\x26\= x61/' # \x26 =3D=3D '&'
&a // replace to &
<= div># echo z | sed 's/z/&\x61/'
za=C2=A0 // execute & feature

I try to fix the problem and I hope it will be useful. Sor= ry for my bad English.
https://github.com/0xddaa/sed/comm= it/723fa224c771ecd16913aea8117aa917877bbd38

Si= ncerely,
ddaa

--94eb2c07d8fed2c866056748592e-- ------------=_1521073202-5562-1-- From unknown Tue Aug 19 14:23:02 2025 X-Loop: help-debbugs@gnu.org Subject: bug#30794: Cannot produce backslash through hexadecimal - sed (GNU sed) 4.2.2 Resent-From: Assaf Gordon Original-Sender: "Debbugs-submit" Resent-CC: bug-sed@gnu.org Resent-Date: Thu, 15 Mar 2018 04:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30794 X-GNU-PR-Package: sed X-GNU-PR-Keywords: To: Jim Meyering Cc: 0xddaa <0xddaa@gmail.com>, 30794-done@debbugs.gnu.org Received: via spool by 30794-done@debbugs.gnu.org id=D30794.15210876575124 (code D ref 30794); Thu, 15 Mar 2018 04:21:02 +0000 Received: (at 30794-done) by debbugs.gnu.org; 15 Mar 2018 04:20:57 +0000 Received: from localhost ([127.0.0.1]:33903 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ewKNs-0001Ka-RO for submit@debbugs.gnu.org; Thu, 15 Mar 2018 00:20:57 -0400 Received: from mail-pl0-f43.google.com ([209.85.160.43]:44003) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ewKNr-0001KK-NS for 30794-done@debbugs.gnu.org; Thu, 15 Mar 2018 00:20:56 -0400 Received: by mail-pl0-f43.google.com with SMTP id f23-v6so3034945plr.10 for <30794-done@debbugs.gnu.org>; Wed, 14 Mar 2018 21:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Zspqpo+Z/HNuRite3lOVRE3GV7EKhql7Ehfa7AWlixw=; b=eng14fbV3nKa0y1lfS9cFm5MElSxjiaYLS+ob5p4pPojdZ8a1Drn3qiWfbWshXdBu3 5+niQpf9DcIICBIqmyVg4ZjqfTBplhiSvVxhEVubKE4eAS7TMsHqORV4WxIjSkgblD3+ eAz1Z3Z9OhzYfQQvqkjAIhWoNozTlfdq8DzwCMN+KGLoLHlqY5ptStJwwjcP/ATQHAYg fTfIqIY5YQaTsNt0fPgNQtHalpqjZQzTo8m+0zvITVVyfe0jVj05Ry/kY3r4X/UQGy6i kfHCPzR/NYaumDkeYFnAK/GYO0K0DMpGRrjhbPSqAhL93DQDP30aEtIUiRw8aEzandox ZtMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Zspqpo+Z/HNuRite3lOVRE3GV7EKhql7Ehfa7AWlixw=; b=AOIY5bgIaRe67RruUHgQiHzYslzH35HsA9+Ty62T4O2GseQkRQwb5WGJWFoIpBAAXA VgZV1lhgL2//Wsn0i2fNtewsLYckEJrulmQ6WEqEPbeIKtjm/TruCSxisXDs0O71W3kI Iayzei1gDwpwLat5dExTUeH+dlYKHUbElgzeT0giLcmk7sNfgqE8LUu+9aCujy2uuijn 55HAZDfZg6nwK6IET/aclYGUSnvTqbqG3IOReu2IfVBVTz1Jwp+p7J618fyhtfG8TjBx nu0ocrOOy3Ec5eurlarFGsKX5tKoCfsovVKfd7kNc8LWd0BmxQ6PbaQ+fSvLF0/dBVHr tpeg== X-Gm-Message-State: AElRT7FR8xMbmWjt9ZLqc9JY5euOezr0/LyYi6sKDhSABqdueLQQMxMA qQAjn3PhFSPTsAKC226IGD4= X-Google-Smtp-Source: AG47ELspWu52Qx2O4gXyCNR4jE3ZGWp8c2omF9Q5ZCEQJzK2AgMcv1TA9BtNXW6RtuzwigzXLOuPkg== X-Received: by 2002:a17:902:d03:: with SMTP id 3-v6mr6541430plu.245.1521087649860; Wed, 14 Mar 2018 21:20:49 -0700 (PDT) Received: from tomato (moose.housegordon.com. [184.68.105.38]) by smtp.gmail.com with ESMTPSA id g5sm7291031pfh.6.2018.03.14.21.20.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 21:20:48 -0700 (PDT) Date: Wed, 14 Mar 2018 22:20:46 -0600 From: Assaf Gordon Message-ID: <20180315042046.GA29079@tomato> References: <20180314024532.GA422@tomato> <20180314223418.GB422@tomato> <20180314224311.GC422@tomato> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On Wed, Mar 14, 2018 at 05:18:43PM -0700, Jim Meyering wrote: > On Wed, Mar 14, 2018 at 3:43 PM, Assaf Gordon wrote: > > > > OK to push? > > Sure. Re the "bug present since..." issue, my intent was to convey > that \x5c never worked the way we now consider correct. Thanks. pushed here: https://git.savannah.gnu.org/cgit/sed.git/commit/?id=b5f5236a4b3a2d6c2f89fb99d614486a65a40a24 regards, - assaf