GNU bug report logs - #47859
Additional seq outlandish example: seq 0 dangers

Previous Next

Package: coreutils;

Reported by: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>

Date: Sun, 18 Apr 2021 01:27:02 UTC

Severity: minor

To reply to this bug, email your comments to 47859 AT debbugs.gnu.org.

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-coreutils <at> gnu.org:
bug#47859; Package coreutils. (Sun, 18 Apr 2021 01:27:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Sun, 18 Apr 2021 01:27:02 GMT) Full text and rfc822 format available.

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

From: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>
To: bug-coreutils <at> gnu.org
Subject: Additional seq outlandish example: seq 0 dangers
Date: Sun, 18 Apr 2021 09:26:28 +0800
On (info "(coreutils) seq invocation") we read
   Be careful when using ‘seq’ with outlandish values: otherwise you
   may...

Here's another 'fun/sad/DDOS yourself' example you might add:

One day I wrote a Makefile,
m:
	seq 0 9|sed s/$$/號.html/|xargs make
but before using it, I though I'll just test with one item,
m:
	seq 0  |sed s/$$/號.html/|xargs make
well of course... as seq prints nothing here,
this triggered a massive ever growing recursive loop...

Yes, all my fault for picking 0. I'll pick 1 next time.

P.S., perhaps document how to get seq to cough up just "0". One way I
found was:
$ seq 0 1 0
0




Information forwarded to bug-coreutils <at> gnu.org:
bug#47859; Package coreutils. (Sun, 18 Apr 2021 06:31:02 GMT) Full text and rfc822 format available.

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

From: Erik Auerswald <auerswal <at> unix-ag.uni-kl.de>
To: 47859 <at> debbugs.gnu.org
Subject: Re: bug#47859: Additional seq outlandish example: seq 0 dangers
Date: Sun, 18 Apr 2021 08:29:59 +0200
Hi,

On Sun, Apr 18, 2021 at 09:26:28AM +0800, 積丹尼 Dan Jacobson wrote:
> On (info "(coreutils) seq invocation") we read
>    Be careful when using ‘seq’ with outlandish values: otherwise you
>    may...
> 
> Here's another 'fun/sad/DDOS yourself' example you might add:
> 
> One day I wrote a Makefile,
> m:
> 	seq 0 9|sed s/$$/號.html/|xargs make
> but before using it, I though I'll just test with one item,
> m:
> 	seq 0  |sed s/$$/號.html/|xargs make
> well of course... as seq prints nothing here,
> this triggered a massive ever growing recursive loop...
> 
> Yes, all my fault for picking 0. I'll pick 1 next time.
> 
> P.S., perhaps document how to get seq to cough up just "0". One way I
> found was:
> $ seq 0 1 0
> 0

I would like to add more information to this bug report with the intent of
helping everybody involved now or in the future.

A slighly simpler method to make 'seq' print just '0' is:

    $ seq 0 0
    0

This is documented, but more generally, e.g., in 'seq --help':

    $ seq --help
    Usage: seq [OPTION]... LAST
      or:  seq [OPTION]... FIRST LAST
      or:  seq [OPTION]... FIRST INCREMENT LAST
    Print numbers from FIRST to LAST, in steps of INCREMENT.
    [...]
    If FIRST or INCREMENT is omitted, it defaults to 1.  [...]
    [...]

Thus, 'seq 0' is the same as 'seq 1 1 0' and 'seq 0 0' is the same as
'seq 0 1 0'.

The default value of '1' for omitted parameters affects other values, too,
not just '0':

    $ seq -1
    $ seq -1 -1
    -1
    $ seq -100000
    $ seq -100000 -100000
    -100000

When "FIRST" and "LAST" are the same, any valid "INCREMENT" value results
in 'seq' printing just one value, not just the default of '1':

    $ seq 0 200 0
    0
    $ seq 0 -200 0
    0
    $ seq 0 0 0
    seq: invalid Zero increment value: ‘0’
    Try 'seq --help' for more information.

Thus IMHO a possible addition to the documentation should probably not
just single out 'seq 0', but mention any number smaller than the default
value for "FIRST" of '1'.

HTH, HAND
Erik
-- 
Inside every large problem is a small problem struggling to get out.
                        -- Hoare's Law of Large Problems




Information forwarded to bug-coreutils <at> gnu.org:
bug#47859; Package coreutils. (Mon, 19 Apr 2021 06:24:02 GMT) Full text and rfc822 format available.

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

From: Bernhard Voelker <mail <at> bernhard-voelker.de>
To: 積丹尼 Dan Jacobson <jidanni <at> jidanni.org>,
 47859 <at> debbugs.gnu.org
Subject: Re: bug#47859: Additional seq outlandish example: seq 0 dangers
Date: Mon, 19 Apr 2021 08:23:41 +0200
On 4/18/21 3:26 AM, 積丹尼 Dan Jacobson wrote:
> Here's another 'fun/sad/DDOS yourself' example you might add:
> 
> One day I wrote a Makefile,
> m:
> 	seq 0 9|sed s/$$/號.html/|xargs make
> but before using it, I though I'll just test with one item,
> m:
> 	seq 0  |sed s/$$/號.html/|xargs make
> well of course... as seq prints nothing here,
> this triggered a massive ever growing recursive loop...
> 
> Yes, all my fault for picking 0. I'll pick 1 next time.

Besides the main discussion about seq(1), I want to add that xargs(1) [0]
is often run most usefully with:

  -r, --no-run-if-empty        if there are no arguments, then do not run COMMAND;
                                 if this option is not given, COMMAND will be
                                 run at least once

Portability hint:
Unfortunately, the -r option is not required by POSIX.  At least, the BSD family
(FreeBSD [1], NetBSD [2], OpenBSD [3]) has it; on Solaris [4], only the '1g'
variant [5] has it.  Not sure about other implementations.

[0] https://www.gnu.org/software/findutils/manual/html_node/find_html/xargs-options.html
[1] https://www.freebsd.org/cgi/man.cgi?xargs
[2] https://man.netbsd.org/xargs.1
[3] https://man.openbsd.org/xargs.1
[4] https://docs.oracle.com/cd/E88353_01/html/E37839/xargs-1.html
[5] https://docs.oracle.com/cd/E88353_01/html/E37839/xargs-1g.html

Have a nice day,
Berny




This bug report was last modified 3 years and 219 days ago.

Previous Next


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