bugGNU Octave - Bugs: bug #29438, regexp: Crash with named...

 
 

bug #29438: regexp: Crash with named subexpressions and nested parentheses

Submitter:  None
Submitted:  Sun 04 Apr 2010 10:15:13 PM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Segfault, Bus Error, etc.
Status:  Fixed Assigned to:  dbateman
Originator Name:  Philipp K. Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 3.3.51
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 13 Apr 2010 09:59:03 PM UTC, comment #4: 

Ok, the savannah tracker doesn't like attached files with the same name.. Here is the second patch again]

D.

David Bateman <dbateman>
Group Member
Tue 13 Apr 2010 09:57:03 PM UTC, comment #3: 

Ok, the fix I posted isn't quite correct and causes another issue. Please find attached an additional patch that should be applied after the first patch

D.

David Bateman <dbateman>
Group Member
Fri 09 Apr 2010 11:33:13 PM UTC, comment #2: 

Its not a matter of failing to initialize a variable, but rather as the original poster pointed out using the grouping operator in the pattern for a named token cases an issue. The reason is that pcre_exec returns a value with the number of matches it finds, but this return value is abused to pass zero-length matches for the parentheses. These zero length matches weren't correctly ignored for named tokens resulting in octave looking for the second named token in an internal array when only one was defined and thus a segfault.

Prove is that although

s = regexp('qwe int asd', ['(?<typestr>(int))'], 'names');

segfaults

s = regexp('qwe int asd', ['(?<typestr>int)'], 'names');

doesn't. Trivial changeset attached that I have pushed


(file #20177)

David Bateman <dbateman>
Group Member
Mon 05 Apr 2010 10:35:08 PM UTC, comment #1: 

We seem to be failing to properly initialize some variables in regexp.  After a single call to regexp all variables are properly initialized and the problem code works.  It is only the first invocation of regexp which has problems.

Working code:
-------------------------------------------------------
sh> octave

octave:1> regexp('a','a')
ans =  1
octave:2> s = regexp('qwe int asd', ['(?<typestr>(int))'], 'names');
octave:3> s
s =
{
  typestr = int
}
--------------------------------------------------------
Failing code:
sh> octave
octave:1> s = regexp('qwe int asd', ['(?<typestr>(int))'], 'names');
--------------------------------------------------------

Rik <rik5>
Group administrator
Sun 04 Apr 2010 10:15:13 PM UTC, original submission:  

Attempting to subgroup a named parenthesized subexpression in a regexp results in a crash, see below for an example.
This happens in a freshly built Octave from the repository as well as the one provided by Ubuntu.

octave:1> ver
----------------------------------------------------------------------
GNU Octave Version 3.3.51+
GNU Octave License: GNU General Public License
Operating System: Linux 2.6.31-20-generic-pae #58-Ubuntu SMP Fri Mar 12 06:25:51 UTC 2010 i686
----------------------------------------------------------------------
no packages installed.
%%                           This is the culprit v   v
octave:2> s = regexp('qwe int asd', ['(?<typestr>(int))'], 'names');
panic: Segmentation fault -- stopping myself...
attempting to save variables to `octave-core'...
save to `octave-core' complete
Segmentation fault

Anonymous

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #20177:  patch.regexp added by dbateman (1KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by dbateman (Updated the item)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by None (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-04-15 dbateman Open/ClosedOpen Closed
    2010-04-09 dbateman Attached File- Added patch.regexp, #20177
        StatusConfirmed Fixed
        Assigned toNone dbateman
    2010-04-05 rik5 StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code