From: Jo-Philipp Wich Date: Sat, 18 Feb 2017 12:48:25 +0000 (+0100) Subject: libopkg: properly fix parse_version() X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=16b176283f668177e3bdd0a13caf88f1b6f2f476;p=oweals%2Fopkg-lede.git libopkg: properly fix parse_version() A previous attempt to fix the verison/revision split caused unterminated strings to get stored in the blob buffer, properly fix this case now. Signed-off-by: Jo-Philipp Wich --- diff --git a/libopkg/pkg_parse.c b/libopkg/pkg_parse.c index 31e7309..f6f0a4d 100644 --- a/libopkg/pkg_parse.c +++ b/libopkg/pkg_parse.c @@ -63,7 +63,7 @@ static void parse_conffiles(pkg_t * pkg, const char *cstr) int parse_version(pkg_t * pkg, const char *vstr) { - char *colon, *rev; + char *colon, *dup, *rev; if (strncmp(vstr, "Version:", 8) == 0) vstr += 8; @@ -81,15 +81,18 @@ int parse_version(pkg_t * pkg, const char *vstr) vstr = ++colon; } - rev = strrchr(vstr, '-'); + + dup = xstrdup(vstr); + rev = strrchr(dup, '-'); if (rev) { - pkg_set_string(pkg, PKG_REVISION, rev + 1); - pkg_set_raw(pkg, PKG_VERSION, vstr, rev - vstr - 1); - } else { - pkg_set_string(pkg, PKG_VERSION, vstr); + *rev++ = '\0'; + pkg_set_string(pkg, PKG_REVISION, rev); } + pkg_set_string(pkg, PKG_VERSION, dup); + free(dup); + return 0; }