Blob Blame History Raw
From cddf43a56f19711866371f02f378dc4095b0fadd Mon Sep 17 00:00:00 2001
From: Lubos Kardos <lkardos@redhat.com>
Date: Mon, 25 Apr 2016 14:38:47 +0200
Subject: [PATCH 2/2] Fix sigsegv in stringFormat() (rhbz:1316903)

Just skip duping of NULL and return it. Returned NULL is handled in
upper layer.
---
 lib/formats.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/formats.c b/lib/formats.c
index e3626ed..bad0b2d 100644
--- a/lib/formats.c
+++ b/lib/formats.c
@@ -44,9 +44,12 @@ static char * stringFormat(rpmtd td)
 	case RPM_NUMERIC_CLASS:
 	    rasprintf(&val, "%" PRIu64, rpmtdGetNumber(td));
 	    break;
-	case RPM_STRING_CLASS:
-	    val = xstrdup(rpmtdGetString(td));
+	case RPM_STRING_CLASS: {
+	    const char *str = rpmtdGetString(td);
+	    if (str)
+		val = xstrdup(str);
 	    break;
+	}
 	case RPM_BINARY_CLASS:
 	    val = pgpHexStr(td->data, td->count);
 	    break;
-- 
1.9.3