fixed dereferencing bug caused by bool type redefinition

This commit is contained in:
Andreas Steffen
2009-08-02 16:58:32 +02:00
parent f35f229fd6
commit 10c13ed264
+51 -17
View File
@@ -261,8 +261,7 @@ static const token_info_t token_info[] =
{ ARG_STR, offsetof(starter_end_t, iface), NULL } { ARG_STR, offsetof(starter_end_t, iface), NULL }
}; };
static void static void free_list(char **list)
free_list(char **list)
{ {
char **s; char **s;
@@ -273,22 +272,25 @@ free_list(char **list)
free(list); free(list);
} }
char ** char** new_list(char *value)
new_list(char *value)
{ {
char *val, *b, *e, *end, **ret; char *val, *b, *e, *end, **ret;
int count; int count;
val = value ? clone_str(value) : NULL; val = value ? clone_str(value) : NULL;
if (!val) if (!val)
{
return NULL; return NULL;
}
end = val + strlen(val); end = val + strlen(val);
for (b = val, count = 0; b < end;) for (b = val, count = 0; b < end;)
{ {
for (e = b; ((*e != ' ') && (*e != '\0')); e++); for (e = b; ((*e != ' ') && (*e != '\0')); e++);
*e = '\0'; *e = '\0';
if (e != b) if (e != b)
{
count++; count++;
}
b = e + 1; b = e + 1;
} }
if (count == 0) if (count == 0)
@@ -302,7 +304,9 @@ new_list(char *value)
{ {
for (e = b; (*e != '\0'); e++); for (e = b; (*e != '\0'); e++);
if (e != b) if (e != b)
{
ret[count++] = clone_str(b); ret[count++] = clone_str(b);
}
b = e + 1; b = e + 1;
} }
ret[count] = NULL; ret[count] = NULL;
@@ -314,9 +318,8 @@ new_list(char *value)
/* /*
* assigns an argument value to a struct field * assigns an argument value to a struct field
*/ */
bool bool assign_arg(kw_token_t token, kw_token_t first, kw_list_t *kw, char *base,
assign_arg(kw_token_t token, kw_token_t first, kw_list_t *kw, char *base bool *assigned)
, bool *assigned)
{ {
char *p = base + token_info[token].offset; char *p = base + token_info[token].offset;
const char **list = token_info[token].list; const char **list = token_info[token].list;
@@ -435,8 +438,9 @@ assign_arg(kw_token_t token, kw_token_t first, kw_list_t *kw, char *base
/* time in seconds? */ /* time in seconds? */
if (*endptr == '\0' || (*endptr == 's' && endptr[1] == '\0')) if (*endptr == '\0' || (*endptr == 's' && endptr[1] == '\0'))
{
break; break;
}
if (endptr[1] == '\0') if (endptr[1] == '\0')
{ {
if (*endptr == 'm') /* time in minutes? */ if (*endptr == 'm') /* time in minutes? */
@@ -475,8 +479,9 @@ assign_arg(kw_token_t token, kw_token_t first, kw_list_t *kw, char *base
/* free any existing list */ /* free any existing list */
if (*listp != NULL) if (*listp != NULL)
{
free_list(*listp); free_list(*listp);
}
/* create a new list and assign values */ /* create a new list and assign values */
*listp = new_list(kw->value); *listp = new_list(kw->value);
@@ -514,8 +519,7 @@ assign_arg(kw_token_t token, kw_token_t first, kw_list_t *kw, char *base
/* /*
* frees all dynamically allocated arguments in a struct * frees all dynamically allocated arguments in a struct
*/ */
void void free_args(kw_token_t first, kw_token_t last, char *base)
free_args(kw_token_t first, kw_token_t last, char *base)
{ {
kw_token_t token; kw_token_t token;
@@ -553,8 +557,7 @@ free_args(kw_token_t first, kw_token_t last, char *base)
/* /*
* clone all dynamically allocated arguments in a struct * clone all dynamically allocated arguments in a struct
*/ */
void void clone_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
clone_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
{ {
kw_token_t token; kw_token_t token;
@@ -570,22 +573,29 @@ clone_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
} }
} }
static bool static bool cmp_list(char **list1, char **list2)
cmp_list(char **list1, char **list2)
{ {
if ((list1 == NULL) && (list2 == NULL)) if ((list1 == NULL) && (list2 == NULL))
{
return TRUE; return TRUE;
}
if ((list1 == NULL) || (list2 == NULL)) if ((list1 == NULL) || (list2 == NULL))
{
return FALSE; return FALSE;
}
for ( ; *list1 && *list2; list1++, list2++) for ( ; *list1 && *list2; list1++, list2++)
{ {
if (strcmp(*list1,*list2) != 0) if (strcmp(*list1,*list2) != 0)
{
return FALSE; return FALSE;
}
} }
if ((*list1 != NULL) || (*list2 != NULL)) if ((*list1 != NULL) || (*list2 != NULL))
{
return FALSE; return FALSE;
}
return TRUE; return TRUE;
} }
@@ -593,8 +603,7 @@ cmp_list(char **list1, char **list2)
/* /*
* compare all arguments in a struct * compare all arguments in a struct
*/ */
bool bool cmp_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
cmp_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
{ {
kw_token_t token; kw_token_t token;
@@ -606,12 +615,25 @@ cmp_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
switch (token_info[token].type) switch (token_info[token].type)
{ {
case ARG_ENUM: case ARG_ENUM:
if (token_info[token].list == LST_bool)
{
bool *b1 = (bool *)p1;
bool *b2 = (bool *)p2;
if (*b1 != *b2)
{
return FALSE;
}
}
else
{ {
int *i1 = (int *)p1; int *i1 = (int *)p1;
int *i2 = (int *)p2; int *i2 = (int *)p2;
if (*i1 != *i2) if (*i1 != *i2)
{
return FALSE; return FALSE;
}
} }
break; break;
case ARG_UINT: case ARG_UINT:
@@ -620,7 +642,9 @@ cmp_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
u_int *u2 = (u_int *)p2; u_int *u2 = (u_int *)p2;
if (*u1 != *u2) if (*u1 != *u2)
{
return FALSE; return FALSE;
}
} }
break; break;
case ARG_ULNG: case ARG_ULNG:
@@ -630,7 +654,9 @@ cmp_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
unsigned long *l2 = (unsigned long *)p2; unsigned long *l2 = (unsigned long *)p2;
if (*l1 != *l2) if (*l1 != *l2)
{
return FALSE; return FALSE;
}
} }
break; break;
case ARG_TIME: case ARG_TIME:
@@ -639,7 +665,9 @@ cmp_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
time_t *t2 = (time_t *)p2; time_t *t2 = (time_t *)p2;
if (*t1 != *t2) if (*t1 != *t2)
{
return FALSE; return FALSE;
}
} }
break; break;
case ARG_STR: case ARG_STR:
@@ -648,9 +676,13 @@ cmp_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
char **cp2 = (char **)p2; char **cp2 = (char **)p2;
if (*cp1 == NULL && *cp2 == NULL) if (*cp1 == NULL && *cp2 == NULL)
{
break; break;
}
if (*cp1 == NULL || *cp2 == NULL || strcmp(*cp1, *cp2) != 0) if (*cp1 == NULL || *cp2 == NULL || strcmp(*cp1, *cp2) != 0)
{
return FALSE; return FALSE;
}
} }
break; break;
case ARG_LST: case ARG_LST:
@@ -659,7 +691,9 @@ cmp_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
char ***listp2 = (char ***)p2; char ***listp2 = (char ***)p2;
if (!cmp_list(*listp1, *listp2)) if (!cmp_list(*listp1, *listp2))
{
return FALSE; return FALSE;
}
} }
break; break;
default: default: