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

 
 

bug #30639: mxCreateString(NULL) causes segmentation fault

Submitted by:  Alois Schlögl <schloegl>
Submitted on:  Tue 03 Aug 2010 02:10:13 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Segfault, Bus Error, etc.
Status: FixedAssigned to: None
Originator Name: Open/Closed: Closed
Release: 3.2.3Operating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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>
Project 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>
Project 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>
Project 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 File(s):
   
   
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
  • -unavailable- added by jwe (Posted a comment)
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by schloegl (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 5 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 04 Aug 2010 11:48:17 PM UTCjweStatusConfirmed=>Fixed
      Open/ClosedOpen=>Closed
    Wed 04 Aug 2010 09:53:14 PM UTCrik5Attached File-=>Added test_mex2.cpp, #21143
    Tue 03 Aug 2010 07:06:10 PM UTCrik5StatusNone=>Confirmed
    Tue 03 Aug 2010 02:10:13 PM UTCschloeglAttached File-=>Added test_mex.cpp, #21133

    Back to the top


    Powered by Savane 3.1-cleanup1