From: Michael Tremer Date: Fri, 25 Jun 2021 15:46:21 +0000 (+0000) Subject: transaction: Copy input string to stack X-Git-Tag: 0.9.28~1171 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9a649d7ccff77eb3608e85d111a4cd7403e5ed2d;p=pakfire.git transaction: Copy input string to stack asprintf suddently does not seem to be happy when the input and output strings overlap Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/transaction.c b/src/libpakfire/transaction.c index 83fe079c1..fa54e603e 100644 --- a/src/libpakfire/transaction.c +++ b/src/libpakfire/transaction.c @@ -261,17 +261,18 @@ PAKFIRE_EXPORT ssize_t pakfire_transaction_downloadsize(struct pakfire_transacti } static void pakfire_transaction_add_headline(char** str, size_t width, const char* headline) { - asprintf(str, "%s%s\n", *str, headline); + asprintf(str, "%s%s\n", strdup(*str), headline); } static void pakfire_transaction_add_newline(char** str, size_t width) { - asprintf(str, "%s\n", *str); + asprintf(str, "%s\n", strdupa(*str)); } static void pakfire_transaction_add_line(char** str, size_t width, const char* name, const char* arch, const char* version, const char* repo, const char* size) { // XXX need to adapt to size - asprintf(str, "%s %-21s %-8s %-21s %-18s %6s \n", *str, name, arch, version, repo, size); + asprintf(str, "%s %-21s %-8s %-21s %-18s %6s \n", strdupa(*str), + name, arch, version, repo, size); } static void pakfire_transaction_add_package(char** str, size_t width, PakfirePackage pkg) { @@ -298,27 +299,31 @@ static void pakfire_transaction_add_package_change(char** str, size_t width, // Print the new package first pakfire_transaction_add_package(str, width, new_pkg); - asprintf(str, "%s --> %s\n", *str, pakfire_package_get_nevra(old_pkg)); + asprintf(str, "%s --> %s\n", strdupa(*str), pakfire_package_get_nevra(old_pkg)); } static void pakfire_transaction_add_separator(char** str, size_t width) { - while (width-- > 0) - asprintf(str, "%s=", *str); + char* separator = alloca(width + 1); + + // Make separator of appropriate length + for (unsigned int i = 0; i < width; i++) + separator[i] = '='; + separator[width] = '\0'; // newline - asprintf(str, "%s\n", *str); + asprintf(str, "%s%s\n", strdupa(*str), separator); } static void pakfire_transaction_add_usage_line(char** str, size_t width, const char* headline, ssize_t size) { char buffer[128]; pakfire_format_size(buffer, sizeof(buffer) - 1, size); - asprintf(str, "%s%-21s: %s\n", *str, headline, buffer); + asprintf(str, "%s%-21s: %s\n", strdupa(*str), headline, buffer); } PAKFIRE_EXPORT char* pakfire_transaction_dump(struct pakfire_transaction* transaction, size_t width) { char headline[1024]; - char* string = ""; + char* string = strdup(""); Pool* pool = transaction->transaction->pool; const int mode =