]> git.ipfire.org Git - pakfire.git/commitdiff
build: Fix splitting the filelist
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 30 Nov 2022 12:56:14 +0000 (12:56 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 30 Nov 2022 12:56:14 +0000 (12:56 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index 2cf3e64d668a6e070716e5c6d0c88162d2ef3b24..6cd2f44cef887aa6ffa614ab16561808676a3516 100644 (file)
@@ -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;
 }