retitle 355966 mawk: segfault setting RS to invalid regexp
tags 355966 + patch
thanks

Hi,

Devin Bayer wrote:

> $ mawk -v RS='\n|'
> mawk: line 0: regular expression compile failed (missing operand)
> 
> |
> Segmentation fault (core dumped)

Jörgen Tegnér wrote:

--- rexp2.c.orig        2009-01-06 20:05:46.000000000 +0100
+++ rexp2.c     2009-01-06 20:06:33.000000000 +0100
@@ -323,6 +323,8 @@
    register STATE *p ;
    unsigned *lenp ;
 {
+  if (!p) return (char *) 0;
+  
    if (p[0].type == M_STR && p[1].type == M_ACCEPT)
    {
       *lenp = p->len ;

Thanks, Jörgen, for the patch!

A similar fix was applied in mawk 1.3.3-20090711.  Because of Aleksey
Cheusov’s regex patch, the code had moved from rexp2.c to
rexp/rexp4.c.

For context, it is probably worth mentioning that is_string_split()
already returns NULL when its argument is a regexp that does not
represent a literal string.  In that case, a regexp pointing to null
is stored in RS, which is analagous to what normally happens when
an invalid regexp is used.  The compile_error_count was already
incremented, another compile-time error might be reported, and when
it is time to start execution mawk checks compile_error_count and
exits before there is a chance to try to use an invalid value.

Regards,
Jonathan



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to