]> git.ipfire.org Git - pakfire.git/commitdiff
dist: Fix splitting mirror list
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 27 Oct 2022 16:10:37 +0000 (16:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 27 Oct 2022 16:10:37 +0000 (16:10 +0000)
It could happen that an empty string passed as a mirror which caused an
invalid download URL being generated.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/dist.c

index 569526dc388536a4cbbb6f4d9938865ad89d9e3e..1d249bef14e8261419678940044d6412faea387b 100644 (file)
@@ -211,6 +211,8 @@ ERROR:
 static int pakfire_dist_create_downloader_and_mirrorlist(
                struct pakfire* pakfire, struct pakfire_parser* makefile,
                struct pakfire_downloader** downloader, struct pakfire_mirrorlist** mirrorlist) {
+       char* p = NULL;
+
        // Create the downloader
        int r = pakfire_downloader_create(downloader, pakfire);
        if (r) {
@@ -219,10 +221,10 @@ static int pakfire_dist_create_downloader_and_mirrorlist(
        }
 
        // Fetch source_dl
-       char** source_dls = pakfire_parser_get_split(makefile, NULL, "source_dl", ' ');
+       char* source_dl = pakfire_parser_get(makefile, NULL, "source_dl");
 
        // We do not need to create a mirrorlist if this isn't set
-       if (!source_dls)
+       if (!source_dl)
                return 0;
 
        // Create mirrorlist
@@ -233,21 +235,22 @@ static int pakfire_dist_create_downloader_and_mirrorlist(
        }
 
        // Add all mirrors
-       for (char** source_dl = source_dls; *source_dl; source_dl++) {
-               r = pakfire_mirrorlist_add_mirror(*mirrorlist, *source_dl);
+       const char* mirror = strtok_r(source_dl, " ", &p);
+
+       while (mirror) {
+               r = pakfire_mirrorlist_add_mirror(*mirrorlist, mirror);
                if (r)
                        goto ERROR;
+
+               mirror = strtok_r(NULL, " ", &p);
        }
 
        // Success
        r = 0;
 
 ERROR:
-       if (source_dls) {
-               for (char** source_dl = source_dls; *source_dl; source_dl++)
-                       free(*source_dl);
-               free(source_dls);
-       }
+       if (source_dl)
+               free(source_dl);
 
        return r;
 }