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
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.
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.
16 Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
18 rrdtoolmodule.c | 16 +++++++++++++---
19 1 file changed, 13 insertions(+), 3 deletions(-)
21 diff --git a/rrdtoolmodule.c b/rrdtoolmodule.c
22 index dead4ff..4713850 100644
25 @@ -880,9 +880,19 @@ _rrdtool_lastupdate(PyObject *self, PyObject *args)
26 PyDict_SetItemString(ret, "ds", ds_dict);
28 for (i = 0; i < ds_cnt; i++) {
29 - PyDict_SetItemString(ds_dict,
31 - PyRRD_Int_FromString(last_ds[i], NULL, 10));
32 + PyObject* val = Py_None;
35 + if (sscanf(last_ds[i], "%lf", &num) == 1) {
36 + val = PyFloat_FromDouble(num);
42 + PyDict_SetItemString(ds_dict, ds_names[i], val);