Re:curl | sh
by oneeyedpigeon on Monday November 03, 2014 @10:13AM
(#8551117)
Why don't shells NOT execute a command if there's no trailing EOL character, to mitigate this very problem?
[ Parent
| on HN ]
Re:curl | sh
by edwintorok on Monday November 03, 2014 @10:30AM
(#8551228)
Why should shells encourage this behaviour (piping unknown stuff to them?)
You should at least download, verify the size and checksum (if available), take a peek at it, and only then run it.
Because you might be piping known stuff to them. Receiving a partial input stream is not necessarily reliant on networking.
Re:curl | sh
by edwintorok on Monday November 03, 2014 @11:35AM
(#8551674)
OK, but the detection of partial vs complete script is not as simple as 'does last line have EOL'?
There are various builtins that require an end token, like case/esac, if/fi, etc. Do these work properly when truncated at an arbitrary line?
Those control structures do work properly - the shell reads ahead until it finds the end token, and fails if it's absent.
It is true that there remains the problem of potential truncation exactly at the end of a top-level line, but I contend that "it stops running here" is a much easier thing to reason about (and, strictly, could always happen if hit with a SIGKILL anyway) than "does the meaning of this line change if we cut it off in a weird place".