Sloppy errorchecking (lib/rrd.php in 0.8.7b)

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Developers, Moderators

Post Reply
knallfrosch
Posts: 13
Joined: Wed Nov 19, 2008 4:08 pm

Sloppy errorchecking (lib/rrd.php in 0.8.7b)

Post by knallfrosch »

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.

Code: Select all

-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));
How to report this correctly, so that it may be added (or a better fix may be introduced)?

Cheers
Knallfrosch
User avatar
Linegod
Developer
Posts: 1626
Joined: Thu Feb 20, 2003 10:16 am
Location: Canada
Contact:

Post by Linegod »

See the 'Report Bugs' page: http://www.cacti.net/bugs.php
--
Live fast, die young
You're sucking up my bandwidth.

J.P. Pasnak,CD
CCNA, LPIC-1
http://www.warpedsystems.sk.ca
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Reported as http://bugs.cacti.net/view.php?id=1359
Reinhard

Going to fix it now for 088

Fixed
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests