From 9b8d22ebe14a2a6d3f5c8bebee0a3126a72521cc Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 08 May 2013 14:19:58 -0400
Subject: [PATCH] Limit debug log entry (line) size to 4096 characters to prevent memory_limit/preformance issues when debug is enabled (imap, smtp, db)

---
 program/lib/Roundcube/rcube_db.php |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/program/lib/Roundcube/rcube_db.php b/program/lib/Roundcube/rcube_db.php
index 4b9ab13..f8a9bdc 100644
--- a/program/lib/Roundcube/rcube_db.php
+++ b/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 . ';');
         }
     }

--
Gitblit v1.9.1