bugGNU Octave - Bugs: bug #53148, NULL characters not processed...

 
 

bug #53148: NULL characters not processed correctly in *printf() family of functions

Submitter:  Rik <rik5>
Submitted:  Tue 13 Feb 2018 10:23:00 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 14 Feb 2018 04:24:08 PM UTC, comment #3: 

That was fast.  I verified the fix, including testing fscanf, and all seems well.

Rik <rik5>
Group administrator
Wed 14 Feb 2018 07:35:25 AM UTC, comment #2: 

I pushed the following changeset.

  http://hg.savannah.gnu.org/hgweb/octave/rev/ca6a73be15da

I think this minimal fix is sufficient for the format specifiers since the format strings that are ultimately passed to the vasprintf function should only be numeric conversion formats, not the literal text portions of the overall formats.  Those are handled separately.  Similarly, the character string arguments to '%s' or '%c' conversions are also handled separately, not by sending them to vasprintf, so they shouldn't be converted to NUL-terminated strings either.

John W. Eaton <jwe>
Group administrator
Tue 13 Feb 2018 11:08:33 PM UTC, comment #1: 

I added a FIXME note to the code in this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/0c6785fb557c).  There is a call to c_str() on the format specifier in order to turn it into a C style string for submission to the library functions printf or sprintf.  It is at that point that the embedded NULLs become a problem.  Given that we can't change the C library, it might require rewriting the format string to use '%c' and an argument of 0.  This starts to look very painful.

Rik <rik5>
Group administrator
Tue 13 Feb 2018 10:23:00 PM UTC, original submission:  

NULL characters in the format string of a printf() function terminate the string.  This was discovered with sprintf().  For example,


s = sprintf ("B\0B")
s = B
double (s)
ans =  66


This doesn't look magically easy to fix.  For sprintf() an octave_ostrstream object is created (see Fsprintf in file-io.cc) which eventually calls the method str() to return a string object.  Looking in octave-stream.cc this is calling std::ostringstream::str().

Perhaps the stream can be opened in binary format at the beginning, but I don't know what effect that will have on ordinary text sequences like "\n".


Rik <rik5>
Group administrator

 

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

Attach Files:
   
   
Comment:
   

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 jwe (Posted a comment)
  • -email is unavailable- added by rik5 (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.

    Only group members can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-02-14 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2018-02-14 jwe StatusConfirmed Ready For Test

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code