]> git.ipfire.org Git - people/amarx/ipfire-3.x.git/blame - python-rrdtool/patches/python-rrdtool-fix-SEGV.patch
quagga: Pre-create PID directory with correct permissions
[people/amarx/ipfire-3.x.git] / python-rrdtool / patches / python-rrdtool-fix-SEGV.patch
CommitLineData
65c47a01
MT
1From a45ed2ad6f92730a479522c46febb1b56b442aba Mon Sep 17 00:00:00 2001
2From: Michael Tremer <michael.tremer@ipfire.org>
3Date: Mon, 23 Nov 2015 02:15:33 +0000
4Subject: [PATCH] Fix crash in lastupdate() method
5
6When a RRD database contains floating point values, the
7PyRRD_Int_FromString function returns NULL, which will then be tried
8to be put into a dictionary.
9This operation fails as PyDict_SetItemString does not handle NULL
10and the program crashes with SEGV.
11
12This patch parses the value as a floating point number
13and will add that instead. If the value could not be parsed,
14None will be added instead.
15
16Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
17---
18 rrdtoolmodule.c | 16 +++++++++++++---
19 1 file changed, 13 insertions(+), 3 deletions(-)
20
21diff --git a/rrdtoolmodule.c b/rrdtoolmodule.c
22index dead4ff..4713850 100644
23--- a/rrdtoolmodule.c
24+++ b/rrdtoolmodule.c
25@@ -880,9 +880,19 @@ _rrdtool_lastupdate(PyObject *self, PyObject *args)
26 PyDict_SetItemString(ret, "ds", ds_dict);
27
28 for (i = 0; i < ds_cnt; i++) {
29- PyDict_SetItemString(ds_dict,
30- ds_names[i],
31- PyRRD_Int_FromString(last_ds[i], NULL, 10));
32+ PyObject* val = Py_None;
33+
34+ double num;
35+ if (sscanf(last_ds[i], "%lf", &num) == 1) {
36+ val = PyFloat_FromDouble(num);
37+ }
38+
39+ if (!val)
40+ return NULL;
41+
42+ PyDict_SetItemString(ds_dict, ds_names[i], val);
43+ Py_DECREF(val);
44+
45 free(last_ds[i]);
46 free(ds_names[i]);
47 }