GNU bug report logs - #21250
sed: empty label for :/b/t commands

Previous Next

Package: sed;

Reported by: Stephane Chazelas <stephane.chazelas <at> gmail.com>

Date: Thu, 13 Aug 2015 14:39:01 UTC

Severity: normal

Tags: fixed

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 21250 in the body.
You can then email your comments to 21250 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-sed <at> gnu.org:
bug#21250; Package sed. (Thu, 13 Aug 2015 14:39:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stephane Chazelas <stephane.chazelas <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-sed <at> gnu.org. (Thu, 13 Aug 2015 14:39:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Stephane Chazelas <stephane.chazelas <at> gmail.com>
To: bug-sed <at> gnu.org
Subject: sed: empty label for :/b/t commands
Date: Thu, 13 Aug 2015 15:37:54 +0100
Hello.

Not really a bug as such, just a note of how a corner case of
GNU sed syntax parsing is being misused:

Recently, on unix.stackexchange.com, I've seen several times
people (might have been the same person every time) doing things
like:

sed ':;s/../../;t'

That is, define an empty label, and branch on it later on.

There's an example at
https://unix.stackexchange.com/revisions/223003/1
https://unix.stackexchange.com/a/223003

as per the documentation, it's not meant to work that way. The
label for ":" is not optional and "t" or "b" without label are
meant to jump to the end (start a new label).

I've warned that person that relying on an unspecified behaviour
was not a good idea as it may no longer work in the future, but
now if several people follow his example, that may mean it will
become a de-facto feature of GNU sed, and then the sed
maintainers would have to make sure it's not removed in future
versions (and document it).

So maybe it would be a good idea to either remove that
"feature" or make it an official one before its usage becomes
widespread.

In any case the:

sed ': label;s/../../;t label'

syntax is not portable anyway. The POSIX syntax being:

sed -e ': label' -e 's/../../;t label'

or

sed ':label
s/../../;t label'

Note that at the moment, GNU sed is not POSIX in that sed ':a;b'
is meant to define a label called "a;b", but that's going to change
in the next version of the spec where the behaviour will be
unspecified instead (so GNU sed doesn't need to be changed).
http://austingroupbugs.net/view.php?id=945

-- 
Stephane





Information forwarded to bug-sed <at> gnu.org:
bug#21250; Package sed. (Sun, 23 Aug 2015 05:04:02 GMT) Full text and rfc822 format available.

Message #8 received at 21250 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Stephane Chazelas <stephane.chazelas <at> gmail.com>
Cc: 21250 <at> debbugs.gnu.org
Subject: Re: bug#21250: sed: empty label for :/b/t commands
Date: Sat, 22 Aug 2015 22:02:42 -0700
On Thu, Aug 13, 2015 at 7:37 AM, Stephane Chazelas
<stephane.chazelas <at> gmail.com> wrote:
> Hello.
>
> Not really a bug as such, just a note of how a corner case of
> GNU sed syntax parsing is being misused:
>
> Recently, on unix.stackexchange.com, I've seen several times
> people (might have been the same person every time) doing things
> like:
>
> sed ':;s/../../;t'
>
> That is, define an empty label, and branch on it later on.
>
> There's an example at
> https://unix.stackexchange.com/revisions/223003/1
> https://unix.stackexchange.com/a/223003
>
> as per the documentation, it's not meant to work that way. The
> label for ":" is not optional and "t" or "b" without label are
> meant to jump to the end (start a new label).

Thank you for pointing that out.
I am preparing a patch to remove that functionality, making sed do
this, instead:

  $ sed :
  sed: -e expression #1, char 1: ":" lacks a label

Does anyone feel differently?
However, note that I have not surveyed other sed implementations.

> I've warned that person that relying on an unspecified behaviour
> was not a good idea as it may no longer work in the future, but
> now if several people follow his example, that may mean it will
> become a de-facto feature of GNU sed, and then the sed
> maintainers would have to make sure it's not removed in future
> versions (and document it).
>
> So maybe it would be a good idea to either remove that
> "feature" or make it an official one before its usage becomes
> widespread.




Information forwarded to bug-sed <at> gnu.org:
bug#21250; Package sed. (Sun, 23 Aug 2015 12:09:02 GMT) Full text and rfc822 format available.

Message #11 received at 21250 <at> debbugs.gnu.org (full text, mbox):

From: Stephane Chazelas <stephane.chazelas <at> gmail.com>
To: Jim Meyering <jim <at> meyering.net>
Cc: 21250 <at> debbugs.gnu.org
Subject: Re: bug#21250: sed: empty label for :/b/t commands
Date: Sun, 23 Aug 2015 13:08:30 +0100
2015-08-22 22:02:42 -0700, Jim Meyering:
[...]
> I am preparing a patch to remove that functionality, making sed do
> this, instead:
> 
>   $ sed :
>   sed: -e expression #1, char 1: ":" lacks a label
> 
> Does anyone feel differently?
> However, note that I have not surveyed other sed implementations.
[...]

Thanks.

Solaris 11 (/bin/sed or /usr/xpg4/bin/sed):

$ echo aa | sed -e : -e s/a/b/ -e t
ba

(it doesn't complain on :, but t branches to the end, not to
that empty label).

Same with busybox sed.

With FreeBSD sed:

$ echo aa | sed -e : -e s/a/b/ -e t
sed: 1: ":
": empty label

(exit status: 1)

-- 
Stephane




Information forwarded to bug-sed <at> gnu.org:
bug#21250; Package sed. (Mon, 24 Aug 2015 04:55:02 GMT) Full text and rfc822 format available.

Message #14 received at 21250 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Stephane Chazelas <stephane.chazelas <at> gmail.com>
Cc: 21250 <at> debbugs.gnu.org
Subject: Re: bug#21250: sed: empty label for :/b/t commands
Date: Sun, 23 Aug 2015 21:54:30 -0700
[Message part 1 (text/plain, inline)]
On Sun, Aug 23, 2015 at 5:08 AM, Stephane Chazelas
<stephane.chazelas <at> gmail.com> wrote:
> 2015-08-22 22:02:42 -0700, Jim Meyering:
> [...]
>> I am preparing a patch to remove that functionality, making sed do
>> this, instead:
>>
>>   $ sed :
>>   sed: -e expression #1, char 1: ":" lacks a label
>>
>> Does anyone feel differently?
>> However, note that I have not surveyed other sed implementations.
> [...]
>
> Thanks.
>
> Solaris 11 (/bin/sed or /usr/xpg4/bin/sed):
>
> $ echo aa | sed -e : -e s/a/b/ -e t
> ba
>
> (it doesn't complain on :, but t branches to the end, not to
> that empty label).
>
> Same with busybox sed.
>
> With FreeBSD sed:
>
> $ echo aa | sed -e : -e s/a/b/ -e t
> sed: 1: ":
> ": empty label
>
> (exit status: 1)

Thanks for checking those.
Here's the patch I expect to push tomorrow:
[0001-sed-reject-a-command-without-a-label.patch (text/x-patch, attachment)]

Added tag(s) fixed. Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 25 Jan 2017 02:30:03 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 21250 <at> debbugs.gnu.org and Stephane Chazelas <stephane.chazelas <at> gmail.com> Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 25 Jan 2017 02:30:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-sed <at> gnu.org:
bug#21250; Package sed. (Wed, 25 Jan 2017 02:30:04 GMT) Full text and rfc822 format available.

Message #21 received at 21250-done <at> debbugs.gnu.org (full text, mbox):

From: Assaf Gordon <assafgordon <at> gmail.com>
To: 21250-done <at> debbugs.gnu.org
Subject: Re: bug#21250: sed: empty label for :/b/t commands
Date: Wed, 25 Jan 2017 02:28:34 +0000
tags 21250 fixed
close 21250
stop

Hello,

This fix has been commited here:
http://git.savannah.gnu.org/cgit/sed.git/commit/?id=31c84cbcfd2516e2

And was included in the recently released sed-4.3:

 $ echo aa | sed -e : -e s/a/b/ -e t
 sed: -e expression #1, char 1: ":" lacks a label


I'm marking this as 'done'.

regards,
- assaf




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 22 Feb 2017 12:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 171 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.