parse: perform stringops on stack bufferspace as to avoid overruns

feature/tap-sh
William Pitcock 2011-07-26 19:26:56 -05:00
parent 045257bebe
commit 0142cc68d4
1 changed files with 27 additions and 10 deletions

37
parse.c
View File

@ -174,12 +174,16 @@ parse_deplist(pkg_t *pkg, const char *depends)
pkg_dependency_t *deplist = NULL; pkg_dependency_t *deplist = NULL;
pkg_dependency_t *deplist_head = NULL; pkg_dependency_t *deplist_head = NULL;
pkg_comparator_t compare = PKG_ANY; pkg_comparator_t compare = PKG_ANY;
char buf[BUFSIZ];
char *kvdepends = strdup_parse(pkg, depends); char *kvdepends = strdup_parse(pkg, depends);
char *start = kvdepends; char *start = buf;
char *ptr = kvdepends; char *ptr = buf;
char *vstart = NULL; char *vstart = NULL;
char *package, *version; char *package, *version;
strncpy(buf, kvdepends, BUFSIZ);
free(kvdepends);
while (*ptr) while (*ptr)
{ {
switch (state) switch (state)
@ -235,9 +239,17 @@ parse_deplist(pkg_t *pkg, const char *depends)
if (deplist_head == NULL) if (deplist_head == NULL)
deplist_head = deplist; deplist_head = deplist;
free(package); if (package != NULL)
package = NULL; {
version = NULL; free(package);
package = NULL;
}
if (version != NULL)
{
free(version);
version = NULL;
}
} }
break; break;
@ -276,11 +288,17 @@ parse_deplist(pkg_t *pkg, const char *depends)
if (deplist_head == NULL) if (deplist_head == NULL)
deplist_head = deplist; deplist_head = deplist;
free(package); if (package != NULL)
package = NULL; {
free(package);
package = NULL;
}
free(version); if (version != NULL)
version = NULL; {
free(version);
version = NULL;
}
} }
if (state == OUTSIDE_MODULE) if (state == OUTSIDE_MODULE)
@ -291,7 +309,6 @@ parse_deplist(pkg_t *pkg, const char *depends)
ptr++; ptr++;
} }
free(kvdepends);
return deplist_head; return deplist_head;
} }