From c027ba7709a86c23038428de15ffed503e67c522 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 06 May 2013 06:07:05 -0400
Subject: [PATCH] Fix bugs caught by static analysis

---
 program/lib/Roundcube/rcube_addressbook.php  |    3 +--
 program/lib/Roundcube/rcube_db_mysql.php     |    2 +-
 program/lib/Roundcube/rcube_vcard.php        |    2 +-
 plugins/password/drivers/sql.php             |    2 +-
 program/lib/utf8.class.php                   |    4 ++--
 program/steps/mail/compose.inc               |    5 +++--
 plugins/acl/acl.php                          |    5 +++--
 program/lib/Roundcube/rcube_imap.php         |    4 ++--
 program/steps/addressbook/func.inc           |    2 +-
 program/lib/Roundcube/rcube_spellchecker.php |    2 +-
 program/steps/addressbook/import.inc         |    4 ++--
 program/steps/addressbook/show.inc           |    2 +-
 program/lib/Roundcube/rcube_imap_generic.php |    8 ++++----
 13 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/plugins/acl/acl.php b/plugins/acl/acl.php
index 938287b..8879a60 100644
--- a/plugins/acl/acl.php
+++ b/plugins/acl/acl.php
@@ -433,8 +433,9 @@
         $acl   = trim(rcube_utils::get_input_value('_acl', rcube_utils::INPUT_GPC));
         $oldid = trim(rcube_utils::get_input_value('_old', rcube_utils::INPUT_GPC));
 
-        $acl   = array_intersect(str_split($acl), $this->rights_supported());
-        $users = $oldid ? array($user) : explode(',', $user);
+        $acl    = array_intersect(str_split($acl), $this->rights_supported());
+        $users  = $oldid ? array($user) : explode(',', $user);
+        $result = 0;
 
         foreach ($users as $user) {
             $user = trim($user);
diff --git a/plugins/password/drivers/sql.php b/plugins/password/drivers/sql.php
index e02bff1..de9ea0a 100644
--- a/plugins/password/drivers/sql.php
+++ b/plugins/password/drivers/sql.php
@@ -183,7 +183,7 @@
         $res = $db->query($sql, $sql_vars);
 
         if (!$db->is_error()) {
-            if (strtolower(substr(trim($query),0,6))=='select') {
+            if (strtolower(substr(trim($sql),0,6)) == 'select') {
                 if ($result = $db->fetch_array($res))
                     return PASSWORD_SUCCESS;
             } else {
diff --git a/program/lib/Roundcube/rcube_addressbook.php b/program/lib/Roundcube/rcube_addressbook.php
index 84bd4bf..a1b29c3 100644
--- a/program/lib/Roundcube/rcube_addressbook.php
+++ b/program/lib/Roundcube/rcube_addressbook.php
@@ -535,7 +535,7 @@
      */
     public static function compose_contact_key($contact, $sort_col)
     {
-        $key = $contact[$sort_col] . ':' . $row['sourceid'];
+        $key = $contact[$sort_col] . ':' . $contact['sourceid'];
 
         // add email to a key to not skip contacts with the same name (#1488375)
         if (!empty($contact['email'])) {
@@ -544,7 +544,6 @@
 
          return $key;
     }
-
 
     /**
      * Compare search value with contact data
diff --git a/program/lib/Roundcube/rcube_db_mysql.php b/program/lib/Roundcube/rcube_db_mysql.php
index 8ab6403..de81ede 100644
--- a/program/lib/Roundcube/rcube_db_mysql.php
+++ b/program/lib/Roundcube/rcube_db_mysql.php
@@ -147,7 +147,7 @@
 
             $result = $this->query('SHOW VARIABLES');
 
-            while ($sql_arr = $this->fetch_array($result)) {
+            while ($row = $this->fetch_array($result)) {
                 $this->variables[$row[0]] = $row[1];
             }
         }
diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php
index c679851..696f485 100644
--- a/program/lib/Roundcube/rcube_imap.php
+++ b/program/lib/Roundcube/rcube_imap.php
@@ -981,7 +981,7 @@
             // use memory less expensive (and quick) method for big result set
             $index = clone $this->index('', $this->sort_field, $this->sort_order);
             // get messages uids for one page...
-            $index->slice($start_msg, min($cnt-$from, $this->page_size));
+            $index->slice($from, min($cnt-$from, $this->page_size));
 
             if ($slice) {
                 $index->slice(-$slice, $slice);
@@ -2727,7 +2727,7 @@
 
         // filter folders list according to rights requirements
         if ($rights && $this->get_capability('ACL')) {
-            $a_folders = $this->filter_rights($a_folders, $rights);
+            $a_mboxes = $this->filter_rights($a_mboxes, $rights);
         }
 
         // filter folders and sort them
diff --git a/program/lib/Roundcube/rcube_imap_generic.php b/program/lib/Roundcube/rcube_imap_generic.php
index db50ffb..fd8b130 100644
--- a/program/lib/Roundcube/rcube_imap_generic.php
+++ b/program/lib/Roundcube/rcube_imap_generic.php
@@ -1077,7 +1077,7 @@
         }
 
         if (!$this->data['READ-WRITE']) {
-            $this->setError(self::ERROR_READONLY, "Mailbox is read-only", 'EXPUNGE');
+            $this->setError(self::ERROR_READONLY, "Mailbox is read-only");
             return false;
         }
 
@@ -1936,7 +1936,7 @@
         }
 
         if (!$this->data['READ-WRITE']) {
-            $this->setError(self::ERROR_READONLY, "Mailbox is read-only", 'STORE');
+            $this->setError(self::ERROR_READONLY, "Mailbox is read-only");
             return false;
         }
 
@@ -1997,7 +1997,7 @@
         }
 
         if (!$this->data['READ-WRITE']) {
-            $this->setError(self::ERROR_READONLY, "Mailbox is read-only", 'STORE');
+            $this->setError(self::ERROR_READONLY, "Mailbox is read-only");
             return false;
         }
 
@@ -2508,7 +2508,7 @@
                 $tokens = $this->tokenizeResponse(preg_replace('/(^\(|\)$)/', '', $line));
 
                 for ($i=0; $i<count($tokens); $i+=2) {
-                    if (preg_match('/^(BODY|BINARY)/i', $token)) {
+                    if (preg_match('/^(BODY|BINARY)/i', $tokens[$i])) {
                         $result = $tokens[$i+1];
                         $found  = true;
                         break;
diff --git a/program/lib/Roundcube/rcube_spellchecker.php b/program/lib/Roundcube/rcube_spellchecker.php
index 2b48fca..60aec50 100644
--- a/program/lib/Roundcube/rcube_spellchecker.php
+++ b/program/lib/Roundcube/rcube_spellchecker.php
@@ -593,7 +593,7 @@
 
         if (empty($plugin['abort'])) {
             $dict = array();
-            $this->rc->db->query(
+            $sql_result = $this->rc->db->query(
                 "SELECT data FROM ".$this->rc->db->table_name('dictionary')
                 ." WHERE user_id ". ($plugin['userid'] ? "= ".$this->rc->db->quote($plugin['userid']) : "IS NULL")
                     ." AND " . $this->rc->db->quoteIdentifier('language') . " = ?",
diff --git a/program/lib/Roundcube/rcube_vcard.php b/program/lib/Roundcube/rcube_vcard.php
index cc3a358..aded4aa 100644
--- a/program/lib/Roundcube/rcube_vcard.php
+++ b/program/lib/Roundcube/rcube_vcard.php
@@ -90,7 +90,7 @@
      */
     public function __construct($vcard = null, $charset = RCUBE_CHARSET, $detect = false, $fieldmap = array())
     {
-        if (!empty($fielmap)) {
+        if (!empty($fieldmap)) {
             $this->extend_fieldmap($fieldmap);
         }
 
diff --git a/program/lib/utf8.class.php b/program/lib/utf8.class.php
index e0dc9e2..0446159 100644
--- a/program/lib/utf8.class.php
+++ b/program/lib/utf8.class.php
@@ -60,8 +60,8 @@
   function loadCharset($charset) {
     
     $charset = preg_replace(array('/^WINDOWS-*125([0-8])$/', '/^CP-/'), array('CP125\\1', 'CP'), $charset);
-    if (isset($aliases[$charset]))
-      $charset = $aliases[$charset];
+    if (isset($this->aliases[$charset]))
+      $charset = $this->aliases[$charset];
     
     $this->charset = $charset;
 
diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc
index ffc0b3b..f0fb433 100644
--- a/program/steps/addressbook/func.inc
+++ b/program/steps/addressbook/func.inc
@@ -167,7 +167,7 @@
     // get address book name (for display)
     if ($abook && $_SESSION['addressbooks_count'] > 1) {
         $name = $abook->get_name();
-        if (!$name && $source == 0) {
+        if (!$name) {
             $name = rcube_label('personaladrbook');
         }
         $OUTPUT->set_env('sourcename', html_entity_decode($name, ENT_COMPAT, 'UTF-8'));
diff --git a/program/steps/addressbook/import.inc b/program/steps/addressbook/import.inc
index 72da150..915aac8 100644
--- a/program/steps/addressbook/import.inc
+++ b/program/steps/addressbook/import.inc
@@ -88,7 +88,7 @@
 
   $content = html::p(null, rcube_label(array(
       'name' => 'importconfirm',
-      'nr' => $IMORT_STATS->inserted,
+      'nr' => $IMPORT_STATS->inserted,
       'vars' => $vars,
     )) . ($IMPORT_STATS->names ? ':' : '.'));
 
@@ -98,7 +98,7 @@
   if ($IMPORT_STATS->skipped) {
       $content .= html::p(null, rcube_label(array(
           'name' => 'importconfirmskipped',
-          'nr' => $IMORT_STATS->skipped,
+          'nr' => $IMPORT_STATS->skipped,
           'vars' => $vars,
         )) . ':');
       $content .= html::p('em', join(', ', array_map('Q', $IMPORT_STATS->skipped_names)));
diff --git a/program/steps/addressbook/show.inc b/program/steps/addressbook/show.inc
index 16be89f..d583a6d 100644
--- a/program/steps/addressbook/show.inc
+++ b/program/steps/addressbook/show.inc
@@ -223,7 +223,7 @@
     }
 
     $hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC)));
-    $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
+    $hiddenfields->add(array('name' => '_cid', 'value' => $contact_id));
 
     $form_start = $RCMAIL->output->request_form(array(
         'name' => "form", 'method' => "post",
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 7205d12..f4a1daf 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -639,7 +639,7 @@
 
 function rcmail_compose_part_body($part, $isHtml = false)
 {
-    global $RCMAIL, $MESSAGE, $compose_mode;
+    global $RCMAIL, $MESSAGE, $LINE_LENGTH, $compose_mode;
 
     // Check if we have enough memory to handle the message in it
     // #1487424: we need up to 10x more memory than the body
@@ -1224,10 +1224,11 @@
 
   // handle attachments in memory
   $data = file_get_contents($path);
+  $name = rcmail_basename($path);
 
   $attachment = array(
     'group' => $COMPOSE['id'],
-    'name' => rcmail_basename($path),
+    'name' => $name,
     'mimetype' => $mimetype ? $mimetype : rc_mime_content_type($path, $name),
     'data' => $data,
     'size' => strlen($data),

--
Gitblit v1.9.1