From 28396110aa31dec67881a46faca71b5d92cc1481 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Tue, 14 Aug 2012 17:01:18 +0200 Subject: [PATCH] Bufferize dependency parsing --- dependency.c | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/dependency.c b/dependency.c index 9070ce0..26de462 100644 --- a/dependency.c +++ b/dependency.c @@ -105,10 +105,12 @@ pkg_dependency_parse_str(pkg_dependency_t *deplist_head, const char *depends) pkg_dependency_t *deplist = NULL; pkg_comparator_t compare = PKG_ANY; char buf[PKG_BUFSIZE]; + char package[PKG_BUFSIZE]; + char version[PKG_BUFSIZE]; char *start = buf; char *ptr = buf; char *vstart = NULL; - char *package = NULL, *version = NULL; +/* char *package = NULL, *version = NULL;*/ strlcpy(buf, depends, sizeof buf); strlcat(buf, " ", sizeof buf); @@ -155,7 +157,8 @@ pkg_dependency_parse_str(pkg_dependency_t *deplist_head, const char *depends) while (PKG_MODULE_SEPARATOR(*iter)) iter++; - package = strndup(iter, ptr - iter); + strlcpy(package, iter, sizeof package); + package[ptr - iter] = '\0'; #if DEBUG_PARSE fprintf(error_msgout, "Found package: %s\n", package); #endif @@ -169,18 +172,6 @@ pkg_dependency_parse_str(pkg_dependency_t *deplist_head, const char *depends) if (deplist_head == NULL) deplist_head = deplist; - if (package != NULL) - { - free(package); - package = NULL; - } - - if (version != NULL) - { - free(version); - version = NULL; - } - compare = PKG_ANY; } @@ -247,7 +238,8 @@ pkg_dependency_parse_str(pkg_dependency_t *deplist_head, const char *depends) case INSIDE_VERSION: if (PKG_MODULE_SEPARATOR(*ptr) || *(ptr + 1) == '\0') { - version = strndup(vstart, (ptr - vstart)); + strlcpy(version, vstart, sizeof version); + version[ptr - vstart] = '\0'; state = OUTSIDE_MODULE; #if DEBUG_PARSE @@ -258,18 +250,6 @@ pkg_dependency_parse_str(pkg_dependency_t *deplist_head, const char *depends) if (deplist_head == NULL) deplist_head = deplist; - if (package != NULL) - { - free(package); - package = NULL; - } - - if (version != NULL) - { - free(version); - version = NULL; - } - compare = PKG_ANY; }