bugGNU Octave - Bugs: bug #30639, mxCreateString(NULL) causes...

 
 

bug #30639: mxCreateString(NULL) causes segmentation fault

Submitter:  Alois Schlögl <schloegl>
Submitted:  Tue 03 Aug 2010 02:10:13 PM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Segfault, Bus Error, etc.
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 3.2.3 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 04 Aug 2010 11:48:17 PM UTC, comment #4: 

I checked in the following changeset:

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

I don't think we should handle NULL in a special way unless it is needed for Matlab compatibility.  If you pass NULL where a valid pointer is expected, you lose.  Too bad.

John W. Eaton <jwe>
Group administrator
Wed 04 Aug 2010 09:53:14 PM UTC, comment #3: 

Your solution works just fine.  However, I think the overall implementation of passed pointers for mex arguments needs to be  reworked.  For example, I can produce a segmentation fault with

mxCreateCellArray (1, NULL)

where, again, a pointer is expected.  Either all of the mex routines that accept pointers need better input validation.  Or the issue needs to be reviewed deeper in the code.  For example, wherever there is a free or delete (there aren't many) it might be worth checking that the ptr is not NULL.

I'm attaching another file, test_mex2.cpp, which illustrates that any NULL pointer passed in will produce a segfault.

(file #21143)

Rik <rik5>
Group administrator
Tue 03 Aug 2010 08:05:30 PM UTC, comment #2: 

In the meantime, I was able to test a solution.
The following patch solves the bug.


diff -r c0ffe159ba1a src/mex.cc
--- a/src/mex.cc Sun Aug 01 14:50:51 2010 -0400
+++ b/src/mex.cc Tue Aug 03 22:01:14 2010 +0200
@@ -2585,7 +2585,10 @@
 mxArray *
 mxCreateString (const char *str)
 {
-  return maybe_mark_array (new mxArray (str));
+  if (str==NULL)
+    return maybe_mark_array (new mxArray (""));
+  else 
+    return maybe_mark_array (new mxArray (str));
 }
 
 mxArray *

Alois Schlögl <schloegl>
Tue 03 Aug 2010 07:06:10 PM UTC, comment #1: 

Confirmed on a recent tip from 8/1/10: 10846:a4f482e66b65.

Rik <rik5>
Group administrator
Tue 03 Aug 2010 02:10:13 PM UTC, original submission:  


mxCreateString(NULL) causes segmentation fault

This can be tested with the attached script.
The desired behavior would be to return an empty string '';

   Alois



$ mkoctfile --mex test_mex.cpp
$ octave -f
GNU Octave, version 3.2.3
Copyright (C) 2009 John W. Eaton and others.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  For details, type `warranty'.

Octave was configured for "x86_64-pc-linux-gnu".

Additional information about Octave is available at http://www.octave.org.

Please contribute if you find this software useful.
For more information, visit http://www.octave.org/help-wanted.html

Report bugs to <bug@octave.org> (but first, please read
http://www.octave.org/bugs.html to learn how to write a helpful report).

For information about changes from previous versions, type `news'.

octave:1> test_mex
panic: Segmentation fault -- stopping myself...
attempting to save variables to `octave-core'...
save to `octave-core' complete
Segmentation fault




Alois Schlögl <schloegl>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #21143:  test_mex2.cpp added by rik5 (579B - text/x-c++src)
file #21133:  test_mex.cpp added by schloegl (743B - text/x-c++src)

 

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 (Posted a comment)
  • -email is unavailable- added by schloegl (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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2010-08-04 jwe StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2010-08-04 rik5 Attached File- Added test_mex2.cpp, #21143
    2010-08-03 rik5 StatusNone Confirmed
    2010-08-03 schloegl Attached File- Added test_mex.cpp, #21133

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code