Discussion:
regcomp crashing
(too old to reply)
Howard West
2004-08-02 22:39:08 UTC
Permalink
I'm trying to use the C runtime regular expression system calls on SCO
OpenServer 5.0.2 and I'm consistently encountering segmentation
violations on some, but not all calls.

I've copied the problem code below. The first call to regcomp
succeeds, the one with the EMPTY_VAL_REGEXP as the expression in
question.

The others terminate with something like this:

401 if(sco_info->pMVRegExp){
(gdb)
402 memset(sco_info->pMVRegExp, '\0', sizeof(regex_t));
(gdb)
403 (status) = regcomp((sco_info->pMVRegExp),
MULTI_VAL_REGEXP, REG_CO
MP_FLAGS);
(gdb)

Program received signal SIGSEGV, Segmentation fault.
0x80023442 in realfree () from /usr/lib/libc.so.1
(gdb)


This code is in a shared library, but I have substantially similar
code running in a command line test program with no trouble at all.
The order of execution don't seem to make any difference. The one
that works is on top because I've rearranged the code and put it there
to prove that it works some of the time. If I move the code around,
the subsequent expressions that break, also break if moved to the head
of the line.

What might be the problem in "realfree()"? Everything in use here is
either dynamically allocated and verified or statically allocated at
compile time.

================================================================================


typedef struct _sco_global {

/* regular expressions for system defaults and extended properties
*/

regex_t * pKeyRegExp;
regex_t * pSVRegExp;
regex_t * pMVRegExp;
regex_t * pNullRegExp;

} SCO_Global;

#define SINGLE_VAL_REGEXP "^\\{([a-z][a-zA-Z_-]+) ([0-9a-zA-Z/:]+)\\}
*"
#define MULTI_VAL_REGEXP "^\\{([a-z][a-zA-Z_-]+) \\{([^\\}]+)\\}\\} *"
#define EMPTY_VAL_REGEXP "^\\{([a-z][a-zA-Z_-]+) \\{\\}\\} *"
#define ENTITY_KEY_REGEXP "^([a-z][0-9a-zA-Z]+)[ \t]+"
#define REG_COMP_FLAGS REG_EXTENDED

sco_info = (SCO_Global *)malloc(sizeof(SCO_Global));

if(!sco_info){
/*
** oops
*/
result = ESA_FATAL;
goto cleanup;
;
}

/* MAKE_REGEXP( (sco_info->pNullRegExp), EMPTY_VAL_REGEXP, status )
*/
/* create null value regexp */
/*
**
** this seems to work
**
*/
(sco_info->pNullRegExp) = (regex_t *)malloc(sizeof(regex_t));
if(sco_info->pNullRegExp){
memset(sco_info->pNullRegExp, '\0', sizeof(regex_t));
(status) = regcomp((sco_info->pNullRegExp), EMPTY_VAL_REGEXP,
REG_COMP_FLAGS);
if((status)) {
processRegExError((status), sco_info->pNullRegExp);
result= ESA_ERR;
goto cleanup;
}
}
else {
goto cleanup;
}

/* create multi value regexp */
/*
**
** this and the remaining ones break
**
*/

(sco_info->pMVRegExp) = (regex_t *)malloc(sizeof(regex_t));
if(sco_info->pMVRegExp){
memset(sco_info->pMVRegExp, '\0', sizeof(regex_t));
(status) = regcomp((sco_info->pMVRegExp), MULTI_VAL_REGEXP,
REG_COMP_FLAGS);
if((status)) {
processRegExError((status), sco_info->pMVRegExp);
result= ESA_ERR;
goto cleanup;
}
}
else {
goto cleanup;
}

/* create entity key value regexp */
(sco_info->pKeyRegExp) = (regex_t *)malloc(sizeof(regex_t));
if(NULL == sco_info->pKeyRegExp){
return -1;
}
(status) = regcomp((sco_info->pKeyRegExp), ("^([a-z][0-9a-zA-Z]+)[
\t]+"), REG_COMP_FLAGS);
if((status)) {
processRegExError((status), sco_info->pKeyRegExp);
}


/* create single value regexp */
(sco_info->pSVRegExp) = (regex_t *)malloc(sizeof(regex_t));
if(ps_SVRegExp){
memset(sco_info->pSVRegExp, '\0', sizeof(regex_t));
(status) = regcomp((sco_info->pSVRegExp), SINGLE_VAL_REGEXP,
REG_COMP_FLAGS);
if((status)) {
processRegExError((status), sco_info->pSVRegExp);
result= ESA_ERR;
goto cleanup;
}
}
else {
goto cleanup;
}
Howard West
2004-08-04 19:21:06 UTC
Permalink
I hope someone out there is reading this, because it is driving me
crazy. Today, I reworked this code a little bit to feed regcomp
strings that had been allocated with strdup() rather than the macro
replacements below. For whatever reason, it began working again, for
about 2 hours and then began failing again.

This time, the crash was not in regcomp(), but in strdup(), a few
lines before the call to regcomp(). The error was the same, SIGSEGV
from realfree().

Could this possibly indicate a bug in the runtime library? I'm not so
arrogant as to think it could only be someone else's problem, but to
see the same error in two different contexts seems odd to me.
Post by Howard West
I'm trying to use the C runtime regular expression system calls on SCO
OpenServer 5.0.2 and I'm consistently encountering segmentation
violations on some, but not all calls.
I've copied the problem code below. The first call to regcomp
succeeds, the one with the EMPTY_VAL_REGEXP as the expression in
question.
401 if(sco_info->pMVRegExp){
(gdb)
402 memset(sco_info->pMVRegExp, '\0', sizeof(regex_t));
(gdb)
403 (status) = regcomp((sco_info->pMVRegExp),
MULTI_VAL_REGEXP, REG_CO
MP_FLAGS);
(gdb)
Program received signal SIGSEGV, Segmentation fault.
0x80023442 in realfree () from /usr/lib/libc.so.1
(gdb)
This code is in a shared library, but I have substantially similar
code running in a command line test program with no trouble at all.
The order of execution don't seem to make any difference. The one
that works is on top because I've rearranged the code and put it there
to prove that it works some of the time. If I move the code around,
the subsequent expressions that break, also break if moved to the head
of the line.
What might be the problem in "realfree()"? Everything in use here is
either dynamically allocated and verified or statically allocated at
compile time.
================================================================================
typedef struct _sco_global {
/* regular expressions for system defaults and extended properties
*/
regex_t * pKeyRegExp;
regex_t * pSVRegExp;
regex_t * pMVRegExp;
regex_t * pNullRegExp;
} SCO_Global;
#define SINGLE_VAL_REGEXP "^\\{([a-z][a-zA-Z_-]+) ([0-9a-zA-Z/:]+)\\}
*"
#define MULTI_VAL_REGEXP "^\\{([a-z][a-zA-Z_-]+) \\{([^\\}]+)\\}\\} *"
#define EMPTY_VAL_REGEXP "^\\{([a-z][a-zA-Z_-]+) \\{\\}\\} *"
#define ENTITY_KEY_REGEXP "^([a-z][0-9a-zA-Z]+)[ \t]+"
#define REG_COMP_FLAGS REG_EXTENDED
sco_info = (SCO_Global *)malloc(sizeof(SCO_Global));
if(!sco_info){
/*
** oops
*/
result = ESA_FATAL;
goto cleanup;
;
}
/* MAKE_REGEXP( (sco_info->pNullRegExp), EMPTY_VAL_REGEXP, status )
*/
/* create null value regexp */
/*
**
** this seems to work
**
*/
(sco_info->pNullRegExp) = (regex_t *)malloc(sizeof(regex_t));
if(sco_info->pNullRegExp){
memset(sco_info->pNullRegExp, '\0', sizeof(regex_t));
(status) = regcomp((sco_info->pNullRegExp), EMPTY_VAL_REGEXP,
REG_COMP_FLAGS);
if((status)) {
processRegExError((status), sco_info->pNullRegExp);
result= ESA_ERR;
goto cleanup;
}
}
else {
goto cleanup;
}
/* create multi value regexp */
/*
**
** this and the remaining ones break
**
*/
(sco_info->pMVRegExp) = (regex_t *)malloc(sizeof(regex_t));
if(sco_info->pMVRegExp){
memset(sco_info->pMVRegExp, '\0', sizeof(regex_t));
(status) = regcomp((sco_info->pMVRegExp), MULTI_VAL_REGEXP,
REG_COMP_FLAGS);
if((status)) {
processRegExError((status), sco_info->pMVRegExp);
result= ESA_ERR;
goto cleanup;
}
}
else {
goto cleanup;
}
/* create entity key value regexp */
(sco_info->pKeyRegExp) = (regex_t *)malloc(sizeof(regex_t));
if(NULL == sco_info->pKeyRegExp){
return -1;
}
(status) = regcomp((sco_info->pKeyRegExp), ("^([a-z][0-9a-zA-Z]+)[
\t]+"), REG_COMP_FLAGS);
if((status)) {
processRegExError((status), sco_info->pKeyRegExp);
}
/* create single value regexp */
(sco_info->pSVRegExp) = (regex_t *)malloc(sizeof(regex_t));
if(ps_SVRegExp){
memset(sco_info->pSVRegExp, '\0', sizeof(regex_t));
(status) = regcomp((sco_info->pSVRegExp), SINGLE_VAL_REGEXP,
REG_COMP_FLAGS);
if((status)) {
processRegExError((status), sco_info->pSVRegExp);
result= ESA_ERR;
goto cleanup;
}
}
else {
goto cleanup;
}
Howard West
2004-08-04 20:09:55 UTC
Permalink
I hope someone out there is reading this, because it is driving me
crazy. Today, I reworked this code a little bit to feed regcomp
strings that had been allocated with strdup() rather than the macro
replacements below. For whatever reason, it began working again, for
about 2 hours and then began failing again.

This time, the crash was not in regcomp(), but in strdup(), a few
lines before the call to regcomp(). The error was the same, SIGSEGV
from realfree().

Could this possibly indicate a bug in the runtime library? I'm not so
arrogant as to think it could only be someone else's problem, but to
see the same error in two different contexts seems odd to me.
Post by Howard West
I'm trying to use the C runtime regular expression system calls on SCO
OpenServer 5.0.2 and I'm consistently encountering segmentation
violations on some, but not all calls.
I've copied the problem code below. The first call to regcomp
succeeds, the one with the EMPTY_VAL_REGEXP as the expression in
question.
401 if(sco_info->pMVRegExp){
(gdb)
402 memset(sco_info->pMVRegExp, '\0', sizeof(regex_t));
(gdb)
403 (status) = regcomp((sco_info->pMVRegExp),
MULTI_VAL_REGEXP, REG_CO
MP_FLAGS);
(gdb)
Program received signal SIGSEGV, Segmentation fault.
0x80023442 in realfree () from /usr/lib/libc.so.1
(gdb)
This code is in a shared library, but I have substantially similar
code running in a command line test program with no trouble at all.
The order of execution don't seem to make any difference. The one
that works is on top because I've rearranged the code and put it there
to prove that it works some of the time. If I move the code around,
the subsequent expressions that break, also break if moved to the head
of the line.
What might be the problem in "realfree()"? Everything in use here is
either dynamically allocated and verified or statically allocated at
compile time.
================================================================================
typedef struct _sco_global {
/* regular expressions for system defaults and extended properties
*/
regex_t * pKeyRegExp;
regex_t * pSVRegExp;
regex_t * pMVRegExp;
regex_t * pNullRegExp;
} SCO_Global;
#define SINGLE_VAL_REGEXP "^\\{([a-z][a-zA-Z_-]+) ([0-9a-zA-Z/:]+)\\}
*"
#define MULTI_VAL_REGEXP "^\\{([a-z][a-zA-Z_-]+) \\{([^\\}]+)\\}\\} *"
#define EMPTY_VAL_REGEXP "^\\{([a-z][a-zA-Z_-]+) \\{\\}\\} *"
#define ENTITY_KEY_REGEXP "^([a-z][0-9a-zA-Z]+)[ \t]+"
#define REG_COMP_FLAGS REG_EXTENDED
sco_info = (SCO_Global *)malloc(sizeof(SCO_Global));
if(!sco_info){
/*
** oops
*/
result = ESA_FATAL;
goto cleanup;
;
}
/* MAKE_REGEXP( (sco_info->pNullRegExp), EMPTY_VAL_REGEXP, status )
*/
/* create null value regexp */
/*
**
** this seems to work
**
*/
(sco_info->pNullRegExp) = (regex_t *)malloc(sizeof(regex_t));
if(sco_info->pNullRegExp){
memset(sco_info->pNullRegExp, '\0', sizeof(regex_t));
(status) = regcomp((sco_info->pNullRegExp), EMPTY_VAL_REGEXP,
REG_COMP_FLAGS);
if((status)) {
processRegExError((status), sco_info->pNullRegExp);
result= ESA_ERR;
goto cleanup;
}
}
else {
goto cleanup;
}
/* create multi value regexp */
/*
**
** this and the remaining ones break
**
*/
(sco_info->pMVRegExp) = (regex_t *)malloc(sizeof(regex_t));
if(sco_info->pMVRegExp){
memset(sco_info->pMVRegExp, '\0', sizeof(regex_t));
(status) = regcomp((sco_info->pMVRegExp), MULTI_VAL_REGEXP,
REG_COMP_FLAGS);
if((status)) {
processRegExError((status), sco_info->pMVRegExp);
result= ESA_ERR;
goto cleanup;
}
}
else {
goto cleanup;
}
/* create entity key value regexp */
(sco_info->pKeyRegExp) = (regex_t *)malloc(sizeof(regex_t));
if(NULL == sco_info->pKeyRegExp){
return -1;
}
(status) = regcomp((sco_info->pKeyRegExp), ("^([a-z][0-9a-zA-Z]+)[
\t]+"), REG_COMP_FLAGS);
if((status)) {
processRegExError((status), sco_info->pKeyRegExp);
}
/* create single value regexp */
(sco_info->pSVRegExp) = (regex_t *)malloc(sizeof(regex_t));
if(ps_SVRegExp){
memset(sco_info->pSVRegExp, '\0', sizeof(regex_t));
(status) = regcomp((sco_info->pSVRegExp), SINGLE_VAL_REGEXP,
REG_COMP_FLAGS);
if((status)) {
processRegExError((status), sco_info->pSVRegExp);
result= ESA_ERR;
goto cleanup;
}
}
else {
goto cleanup;
}
Loading...