[Toybox] sed -e '$a\'

Rob Landley rob at landley.net
Wed Mar 23 11:07:29 PDT 2016



On 03/23/2016 03:45 AM, Patrick Ohly wrote:
> Hello!
> 
> I mentioned on IRC recently that sed -e '$a\' /dev/null segfaults. It
> was pointed out that commit 96a5ed118ce8ad fixes the segfault. I've now
> tried that fix and it indeed fixes the segfault.
> 
> However, the sed invocation above still does not work because Toybox
> complains about the missing text after "a\".

Indeed. The gnu version silently ignores an error.

> No idea whether that is a valid complaint. coreutils accepts it and
> treats it as "add a newline (but only if needed) and then do nothing".

Even gcc will at least warn if you have a continuation with no line
after it:

$ echo '\\' | gcc -E - > /dev/null
<stdin>:1:2: warning: backslash-newline at end of file [enabled by default]

> Debian's update-ca-certificates script uses that to conditionally add a
> newline after a file which may or may not end with a newline:
> http://anonscm.debian.org/cgit/collab-maint/ca-certificates.git/tree/sbin/update-ca-certificates#n100
> 
>   # Add trailing newline to certificate, if it is missing (#635570)
>   sed -e '$a\' "$CERT" >> "$TEMPBUNDLE"

MORE undefined behavior people are relying on. Woo!

Alright, I can remove the error and add a test to sed.test with a
comment about who's doing that.

Thanks,

Rob

 1458756449.0


More information about the Toybox mailing list