bugGNU nano - Bugs: bug #63106, piping text to an external command...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #63106: piping text to an external command fails to decode NUL bytes

Submitter:  Benno Schulenberg <bens>
Submitted:  Mon 26 Sep 2022 09:01:42 AM UTC
   
 
Severity:  2 - Minor Status:  Fixed
Assigned to:  bens Open/Closed:  Closed

Tue 27 Sep 2022 01:51:07 PM UTC, comment #1: 

Fixed in git, commit 1dc2a75c, by running recode_LF_to_NUL() on each line's data before writing it out to the pipe.

Benno Schulenberg <bens>
Group administrator
Mon 26 Sep 2022 09:01:42 AM UTC, original submission:  

When reading text from a file (or from standard input), nano recodes any NUL byte to a linefeed (\n); and when writing out a buffer to a file, nano recodes any embedded linefeed back to a NUL byte.  But when piping text to an external command, this recoding of embedded linefeed to NUL is lacking, resulting in an unintended line break in the text that the external command sees.

To see this happen, run:

printf "one\0two" | src/nano -

See that nano shows "one^@two", where ^@ is the NUL byte.

Now type: ^T | sed 's/o/a/' <Enter>
See that nano now has "ane" and "twa" on two separate lines, which is wrong.

Now do this instead:

printf "one\0two" | sed 's/o/a/' | src/nano -

Now nano shows "ane^@two", which proves that 'sed' sees the text as a single line, as otherwise it would have substituted the second o too.

Well...  Adjusting send_data() in src/files.c to recode any embedded linefeed to NUL will require quite a bit of code... and will get ugly.  I don't know whether it's worth the trouble.

(Bug was found this morning by thinking and suspecting.)

Benno Schulenberg <bens>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bens (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-11-16 bens Open/ClosedOpen Closed
    2022-09-27 bens StatusIn Progress Fixed
        Summarypiping text to a command fails to decode NUL bytes piping text to an external command fails to decode NUL bytes
    2022-09-27 bens StatusNone In Progress
        Assigned toNone bens

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code