Blame SOURCES/0002-reader-make-PY_SSIZE_T_CLEAN.patch

9dd3d1
From ab9f2797127b374665c37c06b02121f5dcf7d61c Mon Sep 17 00:00:00 2001
9dd3d1
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
9dd3d1
Date: Thu, 12 Nov 2020 16:55:56 +0100
9dd3d1
Subject: [PATCH 2/2] reader: make PY_SSIZE_T_CLEAN
9dd3d1
9dd3d1
---
9dd3d1
 systemd/_reader.c | 15 +++++++++++++--
9dd3d1
 1 file changed, 13 insertions(+), 2 deletions(-)
9dd3d1
9dd3d1
diff --git a/systemd/_reader.c b/systemd/_reader.c
9dd3d1
index 8de7f6a963..3b6a4d0bbc 100644
9dd3d1
--- a/systemd/_reader.c
9dd3d1
+++ b/systemd/_reader.c
9dd3d1
@@ -18,7 +18,12 @@
9dd3d1
   along with python-systemd; If not, see <http://www.gnu.org/licenses/>.
9dd3d1
 ***/
9dd3d1
 
9dd3d1
+#define PY_SSIZE_T_CLEAN
9dd3d1
+#pragma GCC diagnostic push
9dd3d1
+#pragma GCC diagnostic ignored "-Wredundant-decls"
9dd3d1
 #include <Python.h>
9dd3d1
+#pragma GCC diagnostic pop
9dd3d1
+
9dd3d1
 #include <structmember.h>
9dd3d1
 #include <datetime.h>
9dd3d1
 #include <time.h>
9dd3d1
@@ -710,11 +715,17 @@ PyDoc_STRVAR(Reader_add_match__doc__,
9dd3d1
              "Match is a string of the form \"FIELD=value\".");
9dd3d1
 static PyObject* Reader_add_match(Reader *self, PyObject *args, PyObject *keywds) {
9dd3d1
         char *match;
9dd3d1
-        int match_len, r;
9dd3d1
+        Py_ssize_t match_len;
9dd3d1
+        int r;
9dd3d1
         if (!PyArg_ParseTuple(args, "s#:add_match", &match, &match_len))
9dd3d1
                 return NULL;
9dd3d1
 
9dd3d1
-        r = sd_journal_add_match(self->j, match, match_len);
9dd3d1
+        if (match_len > INT_MAX) {
9dd3d1
+                set_error(-ENOBUFS, NULL, NULL);
9dd3d1
+                return NULL;
9dd3d1
+        }
9dd3d1
+
9dd3d1
+        r = sd_journal_add_match(self->j, match, (int) match_len);
9dd3d1
         if (set_error(r, NULL, "Invalid match") < 0)
9dd3d1
                 return NULL;
9dd3d1