PHP_VERSION check bug in class.phpmailer.php

Bug #856746 reported by Don Schoeman
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
PHPDevShell
Fix Released
Medium
TitanKing

Bug Description

Both the legacy mailer and new plugin mailer has a PHP version check bug. This is not a PHPDevShell specific bug but rather a bug with the PHPMailer class used by PHPDevShell (class.phpmailer.php).

The issue start on line 1348:

      if (PHP_VERSION < 6) {

        $magic_quotes = get_magic_quotes_runtime();

        set_magic_quotes_runtime(0);

      }

      $file_buffer = file_get_contents($path);

      $file_buffer = $this->EncodeString($file_buffer, $encoding);

      if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); }

Doing a version check using the method above doesn't always work since the PHP_VERSION constant is not always a valid number. When using Ubuntu for example the PHP_VERSION constant will return a string that looks something like this: 5.3.2-1ubuntu4.7

As with the rest of PHPDevShell's code the PHP version_compare() function should be used instead. In the case above the version check is done because the set_magic_quotes_runtime() function has been deprecated. However, the function has already been deprecated from version 5.3.0 meaning that the comparison should be done against PHP v5.3.0 instead of version 6.

I recommend that the code above should be changed to:
      if (version_compare(PHP_VERSION, '5.3.0', '<')) {
        $magic_quotes = get_magic_quotes_runtime();
        set_magic_quotes_runtime(0);
      }
      $file_buffer = file_get_contents($path);
      $file_buffer = $this->EncodeString($file_buffer, $encoding);
      if (version_compare(PHP_VERSION, '5.3.0', '<')) { set_magic_quotes_runtime($magic_quotes); }

I also recommend that the author of the PHPMailer class should be notified of this problem or it should at least be checked if there isn't a later version of the PHPMailer class.

The bug needs to be fixed in both the following files:
includes/legacy/phpmailer/class.phpmailer.php
plugins/PHPMailer/resources/class.phpmailer.php

PHPDevShell version: V 3.0.4-Stable
Browser: Firefox v 4.0.1
OS: Ubuntu 10.04 LTS
Kernel: Linux 2.6.32-28
PHP Version: 5.3.2
MySQL Version: 5.1.41
Apache: 2.2.14

Tags: phpmailer
Revision history for this message
Don Schoeman (don.sch) wrote :
Changed in phpdevshell:
status: New → Confirmed
assignee: nobody → TitanKing (titan-phpdevshell)
Changed in phpdevshell:
status: Confirmed → Fix Committed
Changed in phpdevshell:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.