From eb90fcc50c6b9d995ef1e3292c8d5fcc19ddc146 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Wed, 19 Nov 2014 11:56:16 +0100 Subject: [PATCH] xbps_binpkg_{arch,pkgver}: return a buffer of matched string instead. ... otherwise will pass an invalid pointer to free(3) later on. --- lib/util.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/util.c b/lib/util.c index ad11524c..0361a7ce 100644 --- a/lib/util.c +++ b/lib/util.c @@ -107,7 +107,7 @@ char * xbps_binpkg_pkgver(const char *pkg) { const char *fname; - char *p, *p1; + char *p, *p1, *res; unsigned int len; /* skip path if found, only interested in filename */ @@ -131,14 +131,17 @@ xbps_binpkg_pkgver(const char *pkg) free(p); return NULL; } - return p; + res = strdup(p); + assert(res); + free(p); + return res; } char * xbps_binpkg_arch(const char *pkg) { const char *fname; - char *p; + char *p, *p1, *res; unsigned int len; /* skip path if found, only interested in filename */ @@ -153,8 +156,11 @@ xbps_binpkg_arch(const char *pkg) assert(p); (void)memcpy(p, fname, len); p[len] = '\0'; - - return strrchr(p, '.') + 1; + p1 = strrchr(p, '.') + 1; + assert(p1); + res = strdup(p1); + free(p); + return res; } const char *