Subject: bug#30794: closed (Re: bug#30794: Cannot produce backslash through hexadecimal - sed (GNU sed) 4.2.2)

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 15 Mar 2018 00:20:02 +0000

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 [email-masked].

-- 
30794: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=30794
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#30794: Cannot produce backslash through hexadecimal - sed (GNU sed) 4.2.2
From: Jim Meyering <[email-masked]>
To: Assaf Gordon <[email-masked]>
Cc: 0xddaa <[email-masked]>, [email-masked]
Date: Wed, 14 Mar 2018 17:18:43 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

On Wed, Mar 14, 2018 at 3:43 PM, Assaf Gordon <[email-masked]> 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.

Subject: Cannot produce backslash through hexadecimal - sed (GNU sed) 4.2.2
From: 0xddaa <[email-masked]>
To: [email-masked]
Date: Tue, 13 Mar 2018 18:02:05 +0800
List-Id: <debbugs-submit.debbugs.gnu.org>

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