Changeset 4562 in subversion


Ignore:
Timestamp:
Feb 18, 2011 6:00:48 AM (2 years ago)
Author:
alec
Message:
  • Fix handling of non-safe characters (double-quote, backslash) or UTF-8 characters (dovecot's implementation bug workaround) in script names
Location:
trunk/plugins/managesieve
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/managesieve/Changelog

    r4536 r4562  
    11- Fix fileinto target is always INBOX (#1487776) 
    22- Fix escaping of backslash character in quoted strings (#1487780) 
     3- Fix handling of non-safe characters (double-quote, backslash) 
     4  or UTF-8 characters (dovecot's implementation bug workaround) 
     5  in script names 
    36 
    47* version 4.0 [2011-02-10] 
  • trunk/plugins/managesieve/lib/Net/Sieve.php

    r4495 r4562  
    476476            return PEAR::raiseError('Not currently in TRANSACTION state', 1); 
    477477        } 
    478         if (PEAR::isError($res = $this->_doCmd(sprintf('HAVESPACE "%s" %d', $scriptname, $size)))) { 
     478 
     479        $command = sprintf('HAVESPACE %s %d', $this->_escape($scriptname), $size); 
     480        if (PEAR::isError($res = $this->_doCmd($command))) { 
    479481            return $res; 
    480482        } 
     
    741743            return PEAR::raiseError('Not currently in AUTHORISATION state', 1); 
    742744        } 
    743         if (PEAR::isError($res = $this->_doCmd(sprintf('DELETESCRIPT "%s"', $scriptname)))) { 
     745 
     746        $command = sprintf('DELETESCRIPT %s', $this->_escape($scriptname)); 
     747        if (PEAR::isError($res = $this->_doCmd($command))) { 
    744748            return $res; 
    745749        } 
     
    760764        } 
    761765 
    762         if (PEAR::isError($res = $this->_doCmd(sprintf('GETSCRIPT "%s"', $scriptname)))) { 
     766        $command = sprintf('GETSCRIPT %s', $this->_escape($scriptname)); 
     767        if (PEAR::isError($res = $this->_doCmd($command))) { 
    763768            return $res; 
    764769        } 
     
    780785            return PEAR::raiseError('Not currently in AUTHORISATION state', 1); 
    781786        } 
    782         if (PEAR::isError($res = $this->_doCmd(sprintf('SETACTIVE "%s"', $scriptname)))) { 
     787 
     788        $command = sprintf('SETACTIVE "%s"', $this->_escape($scriptname)); 
     789        if (PEAR::isError($res = $this->_doCmd($command))) { 
    783790            return $res; 
    784791        } 
     792 
    785793        $this->_activeScript = $scriptname; 
    786794        return true; 
     
    809817        foreach ($res as $value) { 
    810818            if (preg_match('/^"(.*)"( ACTIVE)?$/i', $value, $matches)) { 
    811                 $scripts[] = $matches[1]; 
     819                $script_name = stripslashes($matches[1]); 
     820                $scripts[] = $script_name; 
    812821                if (!empty($matches[2])) { 
    813                     $activescript = $matches[1]; 
     822                    $activescript = $script_name; 
    814823                } 
    815824            } 
     
    834843 
    835844        $stringLength = $this->_getLineLength($scriptdata); 
    836  
    837         if (PEAR::isError($res = $this->_doCmd(sprintf("PUTSCRIPT \"%s\" {%d+}\r\n%s", $scriptname, $stringLength, $scriptdata)))) { 
     845        $command      = sprintf("PUTSCRIPT %s {%d+}\r\n%s", 
     846            $this->_escape($scriptname), $stringLength, $scriptdata); 
     847 
     848        if (PEAR::isError($res = $this->_doCmd($command))) { 
    838849            return $res; 
    839850        } 
     
    12141225 
    12151226    /** 
     1227     * Convert string into RFC's quoted-string or literal-c2s form 
     1228     * 
     1229     * @param string $string The string to convert. 
     1230     * 
     1231     * @return string Result string 
     1232     */ 
     1233    function _escape($string) 
     1234    { 
     1235        // Some implementations doesn't allow UTF-8 characters in quoted-string 
     1236        // It's safe to use literal-c2s 
     1237        if (preg_match('/[^\x01-\x09\x0B-\x0C\x0E-\x7F]/', $string)) { 
     1238            return sprintf("{%d+}\r\n%s", $this->_getLineLength($string), $string); 
     1239        } 
     1240 
     1241        return '"' . addcslashes($string, '\\"') . '"'; 
     1242    } 
     1243 
     1244    /** 
    12161245     * Write debug text to the current debug output handler. 
    12171246     * 
Note: See TracChangeset for help on using the changeset viewer.