summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-02-06 19:17:26 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-09-20 09:38:03 -0400
commitffba3a2ff86527103d5fcc09022fe9f35d6ca338 (patch)
treed7810fd8b862335e6da89e35a684e231b63a4f8b
parent8583a45b5cba2f930cce9f0a4eb09909a1277175 (diff)
downloadpython-systemd-ffba3a2ff86527103d5fcc09022fe9f35d6ca338.tar.gz
journal: check errors properly in query_unique
-rw-r--r--systemd/_reader.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/systemd/_reader.c b/systemd/_reader.c
index 34882f3..3b46d17 100644
--- a/systemd/_reader.c
+++ b/systemd/_reader.c
@@ -832,7 +832,8 @@ static PyObject* Reader_query_unique(Reader *self, PyObject *args) {
int r;
const void *uniq;
size_t uniq_len;
- PyObject *value_set, *key, *value;
+ _cleanup_Py_DECREF_ PyObject *_value_set = NULL, *key = NULL;
+ PyObject *value_set;
if (!PyArg_ParseTuple(args, "s:query_unique", &query))
return NULL;
@@ -844,21 +845,35 @@ static PyObject* Reader_query_unique(Reader *self, PyObject *args) {
if (set_error(r, NULL, "Invalid field name") < 0)
return NULL;
- value_set = PySet_New(0);
+ value_set = _value_set = PySet_New(0);
+ if (!value_set)
+ return NULL;
+
key = unicode_FromString(query);
+ if (!key)
+ return NULL;
SD_JOURNAL_FOREACH_UNIQUE(self->j, uniq, uniq_len) {
const char *delim_ptr;
+ _cleanup_Py_DECREF_ PyObject *value = NULL;
delim_ptr = memchr(uniq, '=', uniq_len);
+ if (!delim_ptr) {
+ set_error(-EINVAL, NULL, "Invalid field in the journal");
+ return NULL;
+ }
+
value = PyBytes_FromStringAndSize(
delim_ptr + 1,
(const char*) uniq + uniq_len - (delim_ptr + 1));
- PySet_Add(value_set, value);
- Py_DECREF(value);
+ if (!value)
+ return NULL;
+
+ if (PySet_Add(value_set, value) < 0)
+ return NULL;
}
- Py_DECREF(key);
+ _value_set = NULL;
return value_set;
}