bug#47859: Additional seq outlandish example: seq 0 dangers
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-emptyif 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
bug#47859: Additional seq outlandish example: seq 0 dangers
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 -10 $ seq -10 -10 -10 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
bug#47859: Additional seq outlandish example: seq 0 dangers
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