Bug 12582 – Non-existant named capture groups cause runtime range violation or segmentation fault in regex

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2014-04-15T11:01:00Z
Last change time
2014-04-23T16:03:22Z
Keywords
pull
Assigned to
nobody
Creator
yxcvbasdfgqwert02

Attachments

IDFilenameSummaryContent-TypeSize
1345dvt3.dSource code for test casetext/x-dsrc1712

Comments

Comment #0 by yxcvbasdfgqwert02 — 2014-04-15T11:01:40Z
Created attachment 1345 Source code for test case Trying to get a named capture group which doesn't exist in a regular expression causes a segmentation fault (with -release) or a Range Violation (without -release). Since a segmentation fault can't be catched (at least not with Linux 64 bit), the program reliably crashes. Fix: Throw a descriptive exception instead. In this simple test program, the regular expression could be fixed to avoid the problem. In my complex real-world program, regular expressions are given by the user (configuration file). The program must not crash but has to display an error message containing the regular expression to fix. In dmd 2.065, the SEGV / range violation is caused in regex.d, line 2285: @trusted uint lookupNamedGroup(String)(NamedGroup[] dict, String name) {//equal is @system? auto fnd = assumeSorted!"cmp(a,b) < 0"(map!"a.name"(dict)).lowerBound(name).length; // fnt might be invalid if capture group doesn't exist. // fix: throw an exception if so enforce(equal(dict[fnd].name, name), text("no submatch named ", name)); return dict[fnd].group; }
Comment #1 by dmitry.olsh — 2014-04-23T10:55:01Z
Comment #2 by github-bugzilla — 2014-04-23T16:03:21Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/85ba4748eb9aa78d27e7fce14182ede4dd29ffc0 fix issue 12582 Non-existant named capture groups cause runtime range violation or segmentation fault in regex https://github.com/D-Programming-Language/phobos/commit/63e1836adc5574acb06b7a4ec23e0a401e22cd2f Merge pull request #2106 from DmitryOlshansky/issue-12582 fix issue 12582 Non-existant named capture groups cause runtime range vi...