From 23f431f78063fba9830362884391a7c914077236 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 30 Nov 2022 12:56:14 +0000 Subject: [PATCH] build: Fix splitting the filelist Signed-off-by: Michael Tremer --- src/libpakfire/build.c | 47 ++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 2cf3e64d6..6cd2f44ce 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -314,8 +314,13 @@ static int append_to_array(const char*** array, const char* s) { if (!*array) return 1; - // Append s and terminate the array - (*array)[length] = s; + // Copy the string to the heap + char* p = strdup(s); + if (!p) + return 1; + + // Append p and terminate the array + (*array)[length] = p; (*array)[length + 1] = NULL; return 0; @@ -327,25 +332,30 @@ static int pakfire_build_package_add_files(struct pakfire_build* build, struct pakfire_filelist* filelist = NULL; int r = 1; - char** files = NULL; - const char** includes = NULL; - const char** excludes = NULL; + char** includes = NULL; + char** excludes = NULL; + char* p = NULL; // Fetch filelist from makefile - files = pakfire_parser_get_split(makefile, namespace, "files", '\n'); + char* files = pakfire_parser_get(makefile, namespace, "files"); // No files to package? if (!files) return 0; + const char* file = strtok_r(files, " \n", &p); + // Split into includes and excludes - for (char** file = files; *file; file++) { - if (**file == '!') - r = append_to_array(&excludes, *file + 1); + while (file) { + if (*file == '!') + r = append_to_array(&excludes, file + 1); else - r = append_to_array(&includes, *file); + r = append_to_array(&includes, file); if (r) goto ERROR; + + // Move on to the next token + file = strtok_r(NULL, " \n", &p); } // Allocate a new filelist @@ -354,7 +364,8 @@ static int pakfire_build_package_add_files(struct pakfire_build* build, goto ERROR; // Scan for files - r = pakfire_filelist_scan(filelist, build->buildroot, includes, excludes); + r = pakfire_filelist_scan(filelist, build->buildroot, + (const char**)includes, (const char**)excludes); if (r) goto ERROR; @@ -380,12 +391,18 @@ static int pakfire_build_package_add_files(struct pakfire_build* build, ERROR: if (filelist) pakfire_filelist_unref(filelist); - if (buffer) - free(buffer); - if (includes) + if (files) + free(files); + if (includes) { + for (char** include = includes; *include; include++) + free(*include); free(includes); - if (excludes) + } + if (excludes) { + for (char** exclude = excludes; *exclude; exclude++) + free(*exclude); free(excludes); + } return r; } -- 2.39.5