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

23
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,10 +239,18 @@ parse_deplist(pkg_t *pkg, const char *depends)
if (deplist_head == NULL) if (deplist_head == NULL)
deplist_head = deplist; deplist_head = deplist;
if (package != NULL)
{
free(package); free(package);
package = NULL; package = NULL;
}
if (version != NULL)
{
free(version);
version = NULL; version = NULL;
} }
}
break; break;
@ -276,12 +288,18 @@ parse_deplist(pkg_t *pkg, const char *depends)
if (deplist_head == NULL) if (deplist_head == NULL)
deplist_head = deplist; deplist_head = deplist;
if (package != NULL)
{
free(package); free(package);
package = NULL; package = NULL;
}
if (version != NULL)
{
free(version); free(version);
version = NULL; version = NULL;
} }
}
if (state == OUTSIDE_MODULE) if (state == OUTSIDE_MODULE)
start = ptr; start = ptr;
@ -291,7 +309,6 @@ parse_deplist(pkg_t *pkg, const char *depends)
ptr++; ptr++;
} }
free(kvdepends);
return deplist_head; return deplist_head;
} }