]> git.ipfire.org Git - people/amarx/ipfire-3.x.git/blob - 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
1 From a45ed2ad6f92730a479522c46febb1b56b442aba Mon Sep 17 00:00:00 2001
2 From: Michael Tremer <michael.tremer@ipfire.org>
3 Date: Mon, 23 Nov 2015 02:15:33 +0000
4 Subject: [PATCH] Fix crash in lastupdate() method
5
6 When a RRD database contains floating point values, the
7 PyRRD_Int_FromString function returns NULL, which will then be tried
8 to be put into a dictionary.
9 This operation fails as PyDict_SetItemString does not handle NULL
10 and the program crashes with SEGV.
11
12 This patch parses the value as a floating point number
13 and will add that instead. If the value could not be parsed,
14 None will be added instead.
15
16 Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
17 ---
18 rrdtoolmodule.c | 16 +++++++++++++---
19 1 file changed, 13 insertions(+), 3 deletions(-)
20
21 diff --git a/rrdtoolmodule.c b/rrdtoolmodule.c
22 index 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 }