Blame SOURCES/0001-Return-NULL-string-as-None-from-utf8FromString.patch

83a7c7
From aea53a4aead8bd71f519df35fcffd9eec76fbc01 Mon Sep 17 00:00:00 2001
83a7c7
Message-Id: <aea53a4aead8bd71f519df35fcffd9eec76fbc01.1554884465.git.pmatilai@redhat.com>
83a7c7
From: Panu Matilainen <pmatilai@redhat.com>
83a7c7
Date: Tue, 26 Feb 2019 11:27:51 +0200
83a7c7
Subject: [PATCH] Return NULL string as None from utf8FromString()
83a7c7
83a7c7
Commit 84920f898315d09a57a3f1067433eaeb7de5e830 regressed dnf install
83a7c7
to segfault at the end due to some NULL string passed to strlen().
83a7c7
Check for NULL and return it as None, make it an inline function
83a7c7
to make this saner.
83a7c7
---
83a7c7
 python/rpmsystem-py.h | 10 ++++++++--
83a7c7
 1 file changed, 8 insertions(+), 2 deletions(-)
83a7c7
83a7c7
diff --git a/python/rpmsystem-py.h b/python/rpmsystem-py.h
83a7c7
index 87c750571..25938464a 100644
83a7c7
--- a/python/rpmsystem-py.h
83a7c7
+++ b/python/rpmsystem-py.h
83a7c7
@@ -19,11 +19,17 @@
83a7c7
 #define PyInt_AsSsize_t PyLong_AsSsize_t
83a7c7
 #endif
83a7c7
 
83a7c7
+static inline PyObject * utf8FromString(const char *s)
83a7c7
+{
83a7c7
 /* In Python 3, we return all strings as surrogate-escaped utf-8 */
83a7c7
 #if PY_MAJOR_VERSION >= 3
83a7c7
-#define utf8FromString(_s) PyUnicode_DecodeUTF8(_s, strlen(_s), "surrogateescape")
83a7c7
+    if (s != NULL)
83a7c7
+	return PyUnicode_DecodeUTF8(s, strlen(s), "surrogateescape");
83a7c7
 #else
83a7c7
-#define utf8FromString(_s) PyBytes_FromString(_s)
83a7c7
+    if (s != NULL)
83a7c7
+	return PyBytes_FromString(s);
83a7c7
 #endif
83a7c7
+    Py_RETURN_NONE;
83a7c7
+}
83a7c7
 
83a7c7
 #endif	/* H_SYSTEM_PYTHON */
83a7c7
-- 
83a7c7
2.20.1
83a7c7