Aleksander Machniak
2013-05-08 9b8d22ebe14a2a6d3f5c8bebee0a3126a72521cc
Limit debug log entry (line) size to 4096 characters to prevent
memory_limit/preformance issues when debug is enabled (imap, smtp, db)
3 files modified
28 ■■■■ changed files
program/lib/Roundcube/rcube_db.php 5 ●●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_imap_generic.php 16 ●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_smtp.php 7 ●●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_db.php
@@ -47,6 +47,7 @@
        'identifier_end'   => '"',
    );
    const DEBUG_LINE_LENGTH = 4096;
    /**
     * Factory, returns driver-specific instance of the class
@@ -255,6 +256,10 @@
    protected function debug($query)
    {
        if ($this->options['debug_mode']) {
            if (($len = strlen($query)) > self::DEBUG_LINE_LENGTH) {
                $query = substr_replace($query, "\n-----[debug cut]-----\n",
                    self::DEBUG_LINE_LENGTH/2 - 11, $len - self::DEBUG_LINE_LENGTH - 22);
            }
            rcube::write_log('sql', '[' . (++$this->db_index) . '] ' . $query . ';');
        }
    }
program/lib/Roundcube/rcube_imap_generic.php
@@ -72,6 +72,8 @@
    const COMMAND_CAPABILITY = 2;
    const COMMAND_LASTLINE   = 4;
    const DEBUG_LINE_LENGTH = 4096;
    /**
     * Object constructor
     */
@@ -3757,9 +3759,10 @@
    /**
     * Set the value of the debugging flag.
     *
     * @param   boolean $debug      New value for the debugging flag.
     * @param boolean  $debug   New value for the debugging flag.
     * @param callback $handler Logging handler function
     *
     * @since   0.5-stable
     * @since 0.5-stable
     */
    function setDebug($debug, $handler = null)
    {
@@ -3770,12 +3773,17 @@
    /**
     * Write the given debug text to the current debug output handler.
     *
     * @param   string  $message    Debug mesage text.
     * @param string $message Debug mesage text.
     *
     * @since   0.5-stable
     * @since 0.5-stable
     */
    private function debug($message)
    {
        if (($len = strlen($message)) > self::DEBUG_LINE_LENGTH) {
            $message = substr_replace($message, "\n-----[debug cut]-----\n",
                self::DEBUG_LINE_LENGTH/2 - 11, $len - self::DEBUG_LINE_LENGTH - 22);
        }
        if ($this->resourceid) {
            $message = sprintf('[%s] %s', $this->resourceid, $message);
        }
program/lib/Roundcube/rcube_smtp.php
@@ -33,6 +33,8 @@
    // define headers delimiter
    const SMTP_MIME_CRLF = "\r\n";
    const DEBUG_LINE_LENGTH = 4096;
    /**
     * SMTP Connection and authentication
@@ -327,6 +329,11 @@
     */
    public function debug_handler(&$smtp, $message)
    {
        if (($len = strlen($message)) > self::DEBUG_LINE_LENGTH) {
            $message = substr_replace($message, "\n-----[debug cut]----\n",
                self::DEBUG_LINE_LENGTH/2 - 11, $len - self::DEBUG_LINE_LENGTH - 22);
        }
        rcube::write_log('smtp', preg_replace('/\r\n$/', '', $message));
    }