diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2019-02-26 11:27:51 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2019-02-26 11:31:50 +0200 |
commit | aea53a4aead8bd71f519df35fcffd9eec76fbc01 (patch) | |
tree | ee51b26926b5bd015ebdd293c705b32a4be191b3 /python/rpmsystem-py.h | |
parent | 3e6b0d0fb8a99d3e0d0d6e77a5b73080f9e6a95e (diff) | |
download | rpm-aea53a4aead8bd71f519df35fcffd9eec76fbc01.tar.gz |
Return NULL string as None from utf8FromString()
Commit 84920f898315d09a57a3f1067433eaeb7de5e830 regressed dnf install
to segfault at the end due to some NULL string passed to strlen().
Check for NULL and return it as None, make it an inline function
to make this saner.
Diffstat (limited to 'python/rpmsystem-py.h')
-rw-r--r-- | python/rpmsystem-py.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/python/rpmsystem-py.h b/python/rpmsystem-py.h index 87c750571..25938464a 100644 --- a/python/rpmsystem-py.h +++ b/python/rpmsystem-py.h @@ -19,11 +19,17 @@ #define PyInt_AsSsize_t PyLong_AsSsize_t #endif +static inline PyObject * utf8FromString(const char *s) +{ /* In Python 3, we return all strings as surrogate-escaped utf-8 */ #if PY_MAJOR_VERSION >= 3 -#define utf8FromString(_s) PyUnicode_DecodeUTF8(_s, strlen(_s), "surrogateescape") + if (s != NULL) + return PyUnicode_DecodeUTF8(s, strlen(s), "surrogateescape"); #else -#define utf8FromString(_s) PyBytes_FromString(_s) + if (s != NULL) + return PyBytes_FromString(s); #endif + Py_RETURN_NONE; +} #endif /* H_SYSTEM_PYTHON */ |