From: TheWitness Date: Fri, 15 Nov 2024 13:20:32 +0000 (-0500) Subject: Fix #1268 - Segmentation Fault with Constant Lines X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=866756e4fad639a9c1a403b9601d1038ce7869c6;p=thirdparty%2Frrdtool-1.x.git Fix #1268 - Segmentation Fault with Constant Lines * This issue occurs with the --add-jsontime for lines that are a constant value. In this case, the variable `im->gdes[vidx].step` is always 0, which results in a division by zero segmentation fault. --- diff --git a/CHANGES b/CHANGES index f9f1ddc5..c9b7c1de 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,7 @@ Bugfixes * Fix MacOS Build error (no SOCK_CLOEXEC on mac) @ensc fixes oetiker#1261 * Fix build on 32bits platforms (like armhf) when time_t is 64bits, fixes #1264 * Fix compilation on illumos @hadfl +* Fix division by zero segfault when exporting a LINEx with a constant value Features -------- diff --git a/src/rrd_xport.c b/src/rrd_xport.c index f8a38618..b615b05a 100644 --- a/src/rrd_xport.c +++ b/src/rrd_xport.c @@ -386,14 +386,10 @@ static int rrd_xport_fn( long vidx = im->gdes[ref_list[i]].vidx; time_t now = *start + dst_row * *step; - (*dstptr++) = im->gdes[vidx].data[(unsigned long) - floor((double) - (now - - im->gdes[vidx].start) - / im->gdes[vidx].step) - * im->gdes[vidx].ds_cnt + - im->gdes[vidx].ds]; - + if (im->gdes[vidx].step > 0) { + (*dstptr++) = im->gdes[vidx].data[(unsigned long) + floor((double) (now - im->gdes[vidx].start) / im->gdes[vidx].step) * im->gdes[vidx].ds_cnt + im->gdes[vidx].ds]; + } } }