Menu

#410 SMART Plugin crash (solved/patch)

closed-fixed
nobody
Code (200)
5
2012-03-26
2012-03-24
No Name
No

Hello,

I've tracked down and fixed a bug in the SMART plugin of the latest version 3.0.16. I am running phpSysInfo on a linux Gentoo x64, with Apache v2.2.21 and PHP v5.3.10.
I noticed that you have a number of open bugs with SMART plugin crashing (such as http://sourceforge.net/tracker/?func=detail&aid=3373716&group_id=15&atid=100015\), which may be related.

The SMART plugin will fail to return the smart information, with the apache error_log reporting:

[Sat Mar 24 19:57:36 2012] [notice] child pid 17435 exit signal Segmentation fault (11)
[Sat Mar 24 19:57:36 2012] [notice] child pid 17436 exit signal Segmentation fault (11)
[Sat Mar 24 19:57:38 2012] [notice] child pid 17531 exit signal Segmentation fault (11)
[Sat Mar 24 19:59:42 2012] [notice] child pid 17560 exit signal Segmentation fault (11)

After a debugging session I figured out the problem comes stems from the preg_match of:

class.SMART.inc.php:104 preg_match('/Vendor Specific SMART Attributes with Thresholds\:\n(.*)\n((.|\n)*)\n\nSMART Error Log Version\:/', $result, $vendorInfos);

If the data read from smartctl for a drive are sizeable (in my case around 10k), then preg_match crashes, I believe this has to be or associated with this PHP bug: https://bugs.php.net/bug.php?id=45735
The large output from smartctl comes from disks that have logged errors, below the attributes, which can cause $result to be particularly heavy from the pattern you are using.
To prevent this I have changed it so that there are two preg_matches before the extraction of attributes from $result. First Identify the string offset that the attributes start and then find a potential end. Then extract the attributes from that substring. This is much better and solved the problem for me. The code for this can be inserted on in the place of Line 104:

// set the start and end offset in the result string at the beginning and end respectively
// just in case we don't find the two strings, so that it still works as expected.
$startIndex = 0;
$endIndex = strlen\($result\);

// locate the beginning string offset for the attributes
if \( preg\_match\('/\(Vendor Specific SMART Attributes with Thresholds\)/', $result, $matches, PREG\_OFFSET\_CAPTURE\) \)
\{
    $startIndex = $matches\[0\]\[1\];
\}

// locate the end string offset for the attributes, this is usually right before string "SMART Error Log Version" \(hopefully every output has it\!\)
if \( preg\_match\('/\(SMART Error Log Version\)/', $result, $matches, PREG\_OFFSET\_CAPTURE\) \)
\{
    $endIndex = $matches\[0\]\[1\];
\}

preg\_match\('/Vendor Specific SMART Attributes with Thresholds\:\n\(.\*\)\n\(\(.|\n\)\*\)\n\nSMART Error Log Version\:/', substr \( $result, $startIndex, $endIndex \), $vendorInfos\);

It would be great if you could patch class.SMART.inc.php with this change. I hope this helps.

Discussion

  • Mieczysław Nalewaj

     
  • Mieczysław Nalewaj

    I think that line:
    preg_match('/Vendor Specific SMART Attributes with Thresholds\:\n(.*)\n((.|\n)*)\n\nSMART Error Log Version\:/', substr ( $result, $startIndex, $endIndex ), $vendorInfos);

    should be in the form:
    preg_match('/Vendor Specific SMART Attributes with Thresholds\:\n(.*)\n((.|\n)*)\n\nSMART Error Log Version\:/', substr ( $result, $startIndex, $endIndex - $startIndex), $vendorInfos);

    You can do all this but even simpler. I attach a file class.SMART.inc.php to test.

     
  • No Name

    No Name - 2012-03-24

    namiltd, yes you're it has to be $end - $start, as the third parameter to substr is the length and not the end offset from the start.

    Yes sure, it can be done easier using a preg_match at once:

    preg_match('/Vendor Specific SMART Attributes with Thresholds\:(.*)SMART Error Log Version/s', $result, $matches )

    something like that, where matches[1] will contain the attributes that are between the two strings.
    I guess someone will have to take a decision and merge this or a similar version that addresses the issue.

    cheers.

     
  • No Name

    No Name - 2012-03-24

    works fine, cheers!

     
  • Mieczysław Nalewaj

    • status: open --> closed-fixed