Changeset View
Changeset View
Standalone View
Standalone View
sbin/ccdconfig/ccdconfig.c
Show First 20 Lines • Show All 282 Lines • ▼ Show 20 Lines | |||||
static int | static int | ||||
do_all(int action) | do_all(int action) | ||||
{ | { | ||||
FILE *f; | FILE *f; | ||||
char line[_POSIX2_LINE_MAX]; | char line[_POSIX2_LINE_MAX]; | ||||
char *cp, **argv; | char *cp, **argv; | ||||
int argc, rval; | int argc, rval; | ||||
gid_t egid; | gid_t egid; | ||||
char **nargv; | |||||
rval = 0; | rval = 0; | ||||
egid = getegid(); | egid = getegid(); | ||||
if (setegid(getgid()) != 0) | if (setegid(getgid()) != 0) | ||||
err(1, "setegid failed"); | err(1, "setegid failed"); | ||||
if ((f = fopen(ccdconf, "r")) == NULL) { | if ((f = fopen(ccdconf, "r")) == NULL) { | ||||
if (setegid(egid) != 0) | if (setegid(egid) != 0) | ||||
err(1, "setegid failed"); | err(1, "setegid failed"); | ||||
Show All 11 Lines | if ((cp = strrchr(line, '\n')) != NULL) | ||||
*cp = '\0'; | *cp = '\0'; | ||||
/* Break up the line and pass it's contents to do_single(). */ | /* Break up the line and pass it's contents to do_single(). */ | ||||
if (line[0] == '\0') | if (line[0] == '\0') | ||||
goto end_of_line; | goto end_of_line; | ||||
for (cp = line; (cp = strtok(cp, " \t")) != NULL; cp = NULL) { | for (cp = line; (cp = strtok(cp, " \t")) != NULL; cp = NULL) { | ||||
if (*cp == '#') | if (*cp == '#') | ||||
break; | break; | ||||
if ((argv = realloc(argv, | if ((nargv = realloc(argv, | ||||
sizeof(char *) * ++argc)) == NULL) { | sizeof(char *) * ++argc)) == NULL) { | ||||
warnx("no memory to configure ccds"); | warnx("no memory to configure ccds"); | ||||
return (1); | return (1); | ||||
imp: You still leak argcv here if argv was non-null and the allocation fails. The OpenBSD code is… | |||||
} | } | ||||
argv = nargv; | |||||
argv[argc - 1] = cp; | argv[argc - 1] = cp; | ||||
/* | /* | ||||
* If our action is to unconfigure all, then pass | * If our action is to unconfigure all, then pass | ||||
* just the first token to do_single() and ignore | * just the first token to do_single() and ignore | ||||
* the rest. Since this will be encountered on | * the rest. Since this will be encountered on | ||||
* our first pass through the line, the Right | * our first pass through the line, the Right | ||||
* Thing will happen. | * Thing will happen. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 126 Lines • Show Last 20 Lines |
You still leak argcv here if argv was non-null and the allocation fails. The OpenBSD code is also wrong. Can't tell about the netbsd code since I don't want to go chase down eralloc.