Mantis Bugtracker

Viewing Issue Advanced Details Jump to Notes ] View Simple ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0001359 [Cacti] Graph Management minor have not tried 2009-01-04 12:29 2009-08-29 11:58
Reporter gandalf View Status public  
Assigned To gandalf
Priority normal Resolution fixed Platform
Status closed   OS
Projection none   OS Version
ETA none Fixed in Version 0.8.8 Product Version 0.8.7b
  Target Version Product Build
Summary 0001359: Better error checking in rrd.php
Description http://forums.cacti.net/viewtopic.php?t=30465 [^]
Steps To Reproduce
Additional Information Hi all,
running cacti on a low memory server I stumbled upon a very ghastly error condition. When the system was short on memory apache looped when I tried to open a rrd and threw tons of "fgets(): supplied argument is not a valid stream resource" into the httpd error log file.

It took me a while until I didn't only look at the error itself but the error before that... php wasn't able to popen the rrdtool in lib/rrd.h, line 97 because there wasn't memory left.
The point here is that popen returns $fp as "FALSE" in this case, which isn't the same as "unset". Later on (line 117) it is checked if $fp is set... if it is (but it is false) the script enters a loop (while (!feof($fp)) which will never happen).

I figure it is better to escape this condition and to unset $fp if it won't popen correctly. I figure that the same will happen under Windos, so I added a check there, too.
Tags No tags attached.
Attached Files

- Relationships

-  Notes
(0003707)
gandalf (developer)
2009-01-04 12:30

-bash-3.2# diff -c rrd.php.old rrd.php
*** rrd.php.old Mon Dec 29 15:29:54 2008
--- rrd.php Mon Dec 29 15:30:22 2008
***************
*** 95,100 ****
--- 95,103 ----
                if (sizeof($rrd_struc) == 0) {
                        session_write_close();
                        $fp = popen(read_config_option("path_rrdtool") . escape_command(" $command_line"), "r");
+ if (!$fp) {
+ unset($fp);
+ }
                }else{
                        fwrite(rrd_get_fd($rrd_struc, RRDTOOL_PIPE_CHILD_READ), escape_command(" $command_line") . "\r\n");
                        fflush(rrd_get_fd($rrd_struc, RRDTOOL_PIPE_CHILD_READ));
***************
*** 104,109 ****
--- 107,115 ----
                if (sizeof($rrd_struc) == 0) {
                        session_write_close();
                        $fp = popen(read_config_option("path_rrdtool") . escape_command(" $command_line"), "rb");
+ if (!$fp) {
+ unset($fp);
+ }
                }else{
                        fwrite(rrd_get_fd($rrd_struc, RRDTOOL_PIPE_CHILD_READ), escape_command(" $command_line") . "\r\n");
                        fflush(rrd_get_fd($rrd_struc, RRDTOOL_PIPE_CHILD_READ));
(0003708)
gandalf (developer)
2009-01-04 12:45

SVN#4871

- Issue History
Date Modified Username Field Change
2009-01-04 12:29 gandalf New Issue
2009-01-04 12:30 gandalf Status new => assigned
2009-01-04 12:30 gandalf Assigned To => gandalf
2009-01-04 12:30 gandalf Note Added: 0003707
2009-01-04 12:45 gandalf Note Added: 0003708
2009-01-04 12:45 gandalf Status assigned => resolved
2009-01-04 12:45 gandalf Fixed in Version => 0.8.8
2009-01-04 12:45 gandalf Resolution open => fixed
2009-08-29 11:58 TheWitness Status resolved => closed


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker