[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-ed] Bug in ed-1.5: nul characters are listed as a backslash followe
From: |
Martin Guy |
Subject: |
[Bug-ed] Bug in ed-1.5: nul characters are listed as a backslash followed by a nul character |
Date: |
Sat, 26 Mar 2011 03:16:26 +0100 |
Hi
The 'l' command on a binary file seems to list nul characters as a single \
$ ed /bin/ls
Newline appended
96324
l
[...]
\\\\003\\\\300\002\006\b\300r\001\`\f\\\\\\\\\\ \\\\\
\\\\343\\\\001\\\\\\\\\\\\300r\001\\b\\\\\\\\\\
\\\001\\\\\\\\001\\\\003\\\\\\\\\\\\310r\001\\362\
\\\\\\\\\\\\001\\\\\\\$
This is using Ubuntu 10.10
The culprit is here in io.c: put_tty_line()
char * const p = strchr( escapes, ch );
++col; putchar('\\');
if( p ) putchar( escchars[p-escapes] );
If ch is \0, strchr is matching ch against the trailing nul in
"escapes" and then indexes the trailing nul in escchars.
So those are not single backslashes, they are backslashes followed by
actual nul characters - I've verified this using "script"
A patch to fix this is:
--- ed-1.5.orig/io.c 2011-03-26 03:12:26.059302265 +0100
+++ ed-1.5/io.c 2011-03-26 03:12:56.323302266 +0100
@@ -44,7 +44,7 @@
{
char * const p = strchr( escapes, ch );
++col; putchar('\\');
- if( p ) putchar( escchars[p-escapes] );
+ if( ch && p ) putchar( escchars[p-escapes] );
else
{
col += 2;
Cheers
M
- [Bug-ed] Bug in ed-1.5: nul characters are listed as a backslash followed by a nul character,
Martin Guy <=