[PATCH] fix for an endless loop
"Peter Stamfest" <[email protected]>
| Newsgroups | gmane.comp.db.rrdtool.devel |
|---|---|
| Message-ID | <OFDF54D195.1C505B0F-ONC12577CB.0023DC29-C12577CB.002519BA@domino.stamfest.net> |
Hello, Here is a patch that fixes a serious endless loop problem on 32 bit architectures near the timestamp 2^31 (oh yes - y2k038 is showing its ugly face) when using the graph command(s). Once the endtime of a graph is above the mentioned timestamp, mktime always returns -1 (and correctly so), causing some loops to loop forever. The patch fixes this, causing some strange output, but there is no other sane way to handle this (expect by switching to a 64 bit platform). The patch has seen only light testing, but because it merely handles an error case that usually triggers rarely, its impact should not be too high. That said: I did not test it for daylight saving time switchovers. Sorry for not inlining the patch - the mailer I use these days has its problems with formatting. peter _______________________________________________ rrd-developers mailing list [email protected] https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers
fix-endless-loop.patch
(application/octet-stream, 2.7 KB)
diff -ur rrdtool-1.4.4.002139/src/rrd_graph.c rrdtool-1.4.4.002139-fixed/src/rrd_graph.c
--- rrdtool-1.4.4.002139/src/rrd_graph.c 2010-09-10 11:16:49.000000000 +0200
+++ rrdtool-1.4.4.002139-fixed/src/rrd_graph.c 2010-10-28 23:15:03.000000000 +0200
@@ -1463,6 +1463,13 @@
localtime_r(¤t, &tm);
+ int limit = 2;
+ switch (baseint) {
+ case TMT_SECOND: limit = 7200; break;
+ case TMT_MINUTE: limit = 120; break;
+ case TMT_HOUR: limit = 2; break;
+ default: limit = 2; break;
+ }
do {
switch (baseint) {
case TMT_SECOND:
@@ -1493,7 +1500,7 @@
tm. tm_year += basestep;
}
madetime = mktime(&tm);
- } while (madetime == -1); /* this is necessary to skip impssible times
+ } while (madetime == -1 && limit-- >= 0); /* this is necessary to skip impossible times
like the daylight saving time skips */
return madetime;
@@ -2490,19 +2497,20 @@
mgridtm,
im->xlab_user.
mgridst);
- ti < im->end;
+ ti < im->end && ti != -1;
ti =
find_next_time(ti, im->xlab_user.gridtm, im->xlab_user.gridst)
) {
/* are we inside the graph ? */
if (ti < im->start || ti > im->end)
continue;
- while (timajor < ti) {
+ while (timajor < ti && timajor != -1) {
timajor = find_next_time(timajor,
im->
xlab_user.
mgridtm, im->xlab_user.mgridst);
}
+ if (timajor == -1) break; /* fail in case of problems with time increments */
if (ti == timajor)
continue; /* skip as falls on major grid line */
X0 = xtr(im, ti);
@@ -2526,7 +2534,7 @@
im->
xlab_user.
mgridst);
- ti < im->end;
+ ti < im->end && ti != -1;
ti = find_next_time(ti, im->xlab_user.mgridtm, im->xlab_user.mgridst)
) {
/* are we inside the graph ? */
@@ -2552,9 +2560,9 @@
labtm,
im->xlab_user.
labst);
- ti <=
+ (ti <=
im->end -
- im->xlab_user.precis / 2;
+ im->xlab_user.precis / 2) && ti != -1;
ti = find_next_time(ti, im->xlab_user.labtm, im->xlab_user.labst)
) {
tilab = ti + im->xlab_user.precis / 2; /* correct time for the label */