From 1b954e4120c1565134e9d81296e4fec3ce8e7a7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Fri, 2 Apr 2021 12:22:25 +0200 Subject: [PATCH] Fix segfault in log_internal if prefix is APK_OUT_LOG_ONLY This commit fixes a regression which was introduced in changeset 646c834492a419a96b4032c230e842d27f87e997. If apk_out_fmt() is called while out->log is set and prefix is set to APK_OUT_LOG_ONLY, then apk_out_fmt() would pass this prefix to log_internal() which would, in turn, attempt to write it to standard out using fprintf(). Unfortunately, doing so wont work as intended if prefix is ((char*)-1) (i.e. APK_OUT_LOG_ONLY) and will cause a segmentation fault instead. This commit fixes this segmentation fault by not printing the prefix in log_internal() if it is either NULL or APK_OUT_LOG_ONLY. --- src/print.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/print.c b/src/print.c index cc82c49..0203cbb 100644 --- a/src/print.c +++ b/src/print.c @@ -127,7 +127,7 @@ static int apk_out_get_width(struct apk_out *out) static void log_internal(FILE *dest, const char *prefix, const char *format, va_list va) { if (dest != stdout) fflush(stdout); - if (prefix != NULL) fprintf(dest, "%s", prefix); + if (prefix != NULL && prefix != APK_OUT_LOG_ONLY) fprintf(dest, "%s", prefix); vfprintf(dest, format, va); fprintf(dest, "\n"); fflush(dest);