From 44d7307ae072065b10725d11d420d2813a370a1a Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 27 Oct 2022 16:10:37 +0000 Subject: [PATCH] dist: Fix splitting mirror list It could happen that an empty string passed as a mirror which caused an invalid download URL being generated. Signed-off-by: Michael Tremer --- src/libpakfire/dist.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/libpakfire/dist.c b/src/libpakfire/dist.c index 569526dc..1d249bef 100644 --- a/src/libpakfire/dist.c +++ b/src/libpakfire/dist.c @@ -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; } -- 2.47.3