Howard West
2004-08-02 22:39:08 UTC
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;
}
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;
}