Changeset 82 for branches/1.1dev/lib


Ignore:
Timestamp:
Apr 8, 2006 3:07:57 AM (18 years ago)
Author:
scdev
Message:

Changed all usage of addslashes to mysql_real_escape_quotes

Location:
branches/1.1dev/lib
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/1.1dev/lib/AuthSQL.inc.php

    r81 r82  
    185185            SELECT *, " . $this->_params['user_id_column'] . " AS user_id
    186186            FROM " . $this->_params['user_tbl'] . "
    187             WHERE BINARY username = '" . addslashes($username) . "'
    188             AND BINARY userpass = '" . addslashes($this->encryptPassword($password)) . "'
     187            WHERE BINARY username = '" . mysql_real_escape_string($username) . "'
     188            AND BINARY userpass = '" . mysql_real_escape_string($this->encryptPassword($password)) . "'
    189189        ");
    190190       
     
    331331            $qid = dbQuery("
    332332                SELECT 1 FROM " . $this->_params['user_tbl'] . "
    333                 WHERE " . $this->_params['user_id_column'] . " = '" . addslashes($user_id) . "'
     333                WHERE " . $this->_params['user_id_column'] . " = '" . mysql_real_escape_string($user_id) . "'
    334334                AND DATE_ADD(last_login_datetime, INTERVAL '" . $this->_params['login_timeout'] . "' SECOND) > NOW()
    335335                AND DATE_ADD(last_access_datetime, INTERVAL '" . $this->_params['idle_timeout'] . "' SECOND) > NOW()
     
    444444    {
    445445        if ($this->getFeature('blocking')) {
    446             if (strlen(addslashes($reason)) > 255) {
     446            if (strlen(mysql_real_escape_string($reason)) > 255) {
    447447                // blocked_reason field is varchar(255).
    448448                logMsg(sprintf('Blocked reason provided is greater than 255 characters: %s', $reason), LOG_WARNING, __FILE__, __LINE__);
     
    454454                UPDATE " . $this->_params['user_tbl'] . " SET
    455455                blocked = 'true',
    456                 blocked_reason = '" . addslashes($reason) . "'
    457                 WHERE " . $this->_params['user_id_column'] . " = '" . addslashes($user_id) . "'
     456                blocked_reason = '" . mysql_real_escape_string($reason) . "'
     457                WHERE " . $this->_params['user_id_column'] . " = '" . mysql_real_escape_string($user_id) . "'
    458458            ");
    459459        }
     
    472472                blocked = '',
    473473                blocked_reason = ''
    474                 WHERE " . $this->_params['user_id_column'] . " = '" . addslashes($user_id) . "'
     474                WHERE " . $this->_params['user_id_column'] . " = '" . mysql_real_escape_string($user_id) . "'
    475475            ");
    476476        }
     
    486486    function usernameExists($username)
    487487    {   
    488         $qid = dbQuery("SELECT 1 FROM " . $this->_params['user_tbl'] . " WHERE username = '" . addslashes($username) . "'");
     488        $qid = dbQuery("SELECT 1 FROM " . $this->_params['user_tbl'] . " WHERE username = '" . mysql_real_escape_string($username) . "'");
    489489        return (mysql_num_rows($qid) > 0);
    490490    }
     
    499499    function getUsername($user_id)
    500500    {   
    501         $qid = dbQuery("SELECT " . $this->_params['username_column'] . " FROM " . $this->_params['user_tbl'] . " WHERE " . $this->_params['user_id_column'] . " = '" . addslashes($user_id) . "'");
     501        $qid = dbQuery("SELECT " . $this->_params['username_column'] . " FROM " . $this->_params['user_tbl'] . " WHERE " . $this->_params['user_id_column'] . " = '" . mysql_real_escape_string($user_id) . "'");
    502502        if (list($username) = mysql_fetch_row($qid)) {
    503503            return $username;
     
    577577        dbQuery("
    578578            UPDATE " . $this->_params['user_tbl'] . "
    579             SET userpass = '" . addslashes($this->encryptPassword($password)) . "'
    580             WHERE " . $this->_params['user_id_column'] . " = '" . addslashes($user_id) . "'
     579            SET userpass = '" . mysql_real_escape_string($this->encryptPassword($password)) . "'
     580            WHERE " . $this->_params['user_id_column'] . " = '" . mysql_real_escape_string($user_id) . "'
    581581        ");
    582582    }
     
    600600        $qid = dbQuery("
    601601            SELECT * FROM " . $this->_params['user_tbl'] . "
    602             WHERE " . $this->_params['user_id_column'] . " = '" . addslashes($user_id) . "'
     602            WHERE " . $this->_params['user_id_column'] . " = '" . mysql_real_escape_string($user_id) . "'
    603603        ");
    604604        $user_data = mysql_fetch_assoc($qid);
     
    610610        dbQuery("
    611611            UPDATE " . $this->_params['user_tbl'] . "
    612             SET userpass = '" . addslashes($this->encryptPassword($password)) . "'
    613             WHERE " . $this->_params['user_id_column'] . " = '" . addslashes($user_id) . "'
     612            SET userpass = '" . mysql_real_escape_string($this->encryptPassword($password)) . "'
     613            WHERE " . $this->_params['user_id_column'] . " = '" . mysql_real_escape_string($user_id) . "'
    614614        ");
    615615
  • branches/1.1dev/lib/MySQLSessionHandler.inc.php

    r81 r82  
    5252   
    5353    // Select the data belonging to session $session_id from the MySQL session table   
    54     $qid = mysql_query("SELECT session_data FROM " . $sess_mysql['table'] . " WHERE session_id = '" . addslashes($session_id) . "'", $sess_mysql['dbh']);
     54    $qid = mysql_query("SELECT session_data FROM " . $sess_mysql['table'] . " WHERE session_id = '" . mysql_real_escape_string($session_id) . "'", $sess_mysql['dbh']);
    5555   
    5656    // Check for errors
     
    7575   
    7676    // Write the serialized session data ($session_data) to the MySQL session table
    77     mysql_query("REPLACE INTO " . $sess_mysql['table'] . "(session_id, session_data, last_access) VALUES ('" . addslashes($session_id) . "', '" . addslashes($session_data) . "', null)", $sess_mysql['dbh']);
     77    mysql_query("REPLACE INTO " . $sess_mysql['table'] . "(session_id, session_data, last_access) VALUES ('" . mysql_real_escape_string($session_id) . "', '" . mysql_real_escape_string($session_data) . "', null)", $sess_mysql['dbh']);
    7878   
    7979    // Check for errors
     
    9191
    9292    // Delete from the MySQL table all data for the session $session_id
    93     mysql_query("DELETE FROM " . $sess_mysql['table'] . " WHERE session_id = '" . addslashes($session_id) . "'", $sess_mysql['dbh']);
     93    mysql_query("DELETE FROM " . $sess_mysql['table'] . " WHERE session_id = '" . mysql_real_escape_string($session_id) . "'", $sess_mysql['dbh']);
    9494           
    9595    // Check for errors
  • branches/1.1dev/lib/NodeHeirarchy.inc.php

    r81 r82  
    202202                    title
    203203                ) VALUES (
    204                     '" . addslashes($parent['node_type']) . "',
    205                     '" . addslashes($parent['node_id']) . "',
    206                     '" . addslashes($child_type) . "',
    207                     '" . addslashes($child_id) . "',
    208                     " . (is_null($relationship_type) ? "NULL" : "'" . addslashes($relationship_type) . "'") . ",
    209                     '" . addslashes($title) . "'
     204                    '" . mysql_real_escape_string($parent['node_type']) . "',
     205                    '" . mysql_real_escape_string($parent['node_id']) . "',
     206                    '" . mysql_real_escape_string($child_type) . "',
     207                    '" . mysql_real_escape_string($child_id) . "',
     208                    " . (is_null($relationship_type) ? "NULL" : "'" . mysql_real_escape_string($relationship_type) . "'") . ",
     209                    '" . mysql_real_escape_string($title) . "'
    210210                )
    211211            ");
     
    250250        dbQuery("
    251251            DELETE FROM node_tbl
    252             WHERE child_type = '" . addslashes($child_type) . "'
    253             AND child_id = '" . addslashes($child_id) . "'
     252            WHERE child_type = '" . mysql_real_escape_string($child_type) . "'
     253            AND child_id = '" . mysql_real_escape_string($child_id) . "'
    254254        ");
    255255        logMsg(sprintf('deleteNode: Deleted node %s %s.', $child_type, $child_id), LOG_DEBUG, __FILE__, __LINE__);
     
    316316            $qid = dbQuery("
    317317                SELECT title FROM node_tbl
    318                 WHERE child_type = '" . addslashes($child_type) . "'
    319                 AND child_id = '" . addslashes($child_id) . "'
    320                 AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . addslashes($relationship_type) . "'") . "
     318                WHERE child_type = '" . mysql_real_escape_string($child_type) . "'
     319                AND child_id = '" . mysql_real_escape_string($child_id) . "'
     320                AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . mysql_real_escape_string($relationship_type) . "'") . "
    321321            ");
    322322            list($title) = mysql_fetch_row($qid);
     
    326326        dbQuery("
    327327            DELETE FROM node_tbl
    328             WHERE child_type = '" . addslashes($child_type) . "'
    329             AND child_id = '" . addslashes($child_id) . "'
    330             AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . addslashes($relationship_type) . "'") . "
     328            WHERE child_type = '" . mysql_real_escape_string($child_type) . "'
     329            AND child_id = '" . mysql_real_escape_string($child_id) . "'
     330            AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . mysql_real_escape_string($relationship_type) . "'") . "
    331331        ");
    332332        logMsg(sprintf('moveNode: Deleted node %s %s.', $child_type, $child_id), LOG_DEBUG, __FILE__, __LINE__);
     
    364364                $type_constraint = array($type_constraint);
    365365            }
    366             $in_clause = "AND parent_type IN ('" . join("','", array_map('addslashes', $type_constraint)) . "')";
     366            $in_clause = "AND parent_type IN ('" . join("','", array_map('mysql_real_escape_string', $type_constraint)) . "')";
    367367        }
    368368
     
    370370            SELECT parent_type, parent_id
    371371            FROM node_tbl
    372             WHERE child_type = '" . addslashes($child_type) . "'
    373             AND child_id = '" . addslashes($child_id) . "'
     372            WHERE child_type = '" . mysql_real_escape_string($child_type) . "'
     373            AND child_id = '" . mysql_real_escape_string($child_id) . "'
    374374            $in_clause
    375             " . addslashes($order) . "
     375            " . mysql_real_escape_string($order) . "
    376376        ");
    377377       
     
    410410            SELECT child_type, child_id, title, subnode_quantity
    411411            FROM node_tbl
    412             WHERE child_type = '" . addslashes($child_type) . "'
    413             AND child_id = '" . addslashes($child_id) . "'
     412            WHERE child_type = '" . mysql_real_escape_string($child_type) . "'
     413            AND child_id = '" . mysql_real_escape_string($child_id) . "'
    414414        ");
    415415       
     
    453453                $type_constraint = array($type_constraint);
    454454            }
    455             $in_clause = "AND child_type IN ('" . join("','", array_map('addslashes', $type_constraint)) . "')";
     455            $in_clause = "AND child_type IN ('" . join("','", array_map('mysql_real_escape_string', $type_constraint)) . "')";
    456456        }
    457457       
     
    459459            SELECT *
    460460            FROM node_tbl
    461             WHERE parent_type = '" . addslashes($child_type) . "'
    462             AND parent_id = '" . addslashes($child_id) . "'
     461            WHERE parent_type = '" . mysql_real_escape_string($child_type) . "'
     462            AND parent_id = '" . mysql_real_escape_string($child_id) . "'
    463463            $in_clause
    464             " . addslashes($order) . "
     464            " . mysql_real_escape_string($order) . "
    465465        ");
    466466       
     
    502502                $type_constraint = array($type_constraint);
    503503            }
    504             $in_clause = "AND child_type IN ('" . join("','", array_map('addslashes', $type_constraint)) . "')";
     504            $in_clause = "AND child_type IN ('" . join("','", array_map('mysql_real_escape_string', $type_constraint)) . "')";
    505505        }
    506506
     
    508508            SELECT COUNT(*)
    509509            FROM node_tbl
    510             WHERE parent_type = '" . addslashes($child_type) . "'
    511             AND parent_id = '" . addslashes($child_id) . "'
     510            WHERE parent_type = '" . mysql_real_escape_string($child_type) . "'
     511            AND parent_id = '" . mysql_real_escape_string($child_id) . "'
    512512            $in_clause
    513513        ");
     
    590590            SELECT parent_type, parent_id, child_type, child_id, title, subnode_quantity
    591591            FROM node_tbl
    592             WHERE child_type = '" . addslashes($child_type) . "'
    593             AND child_id = '" . addslashes($child_id) . "'
     592            WHERE child_type = '" . mysql_real_escape_string($child_type) . "'
     593            AND child_id = '" . mysql_real_escape_string($child_id) . "'
    594594        ");
    595595        while ($row = mysql_fetch_assoc($qid)) {
     
    649649            $qid = dbQuery("
    650650                SELECT 1 FROM node_tbl
    651                 WHERE parent_type = '" . addslashes($parent_type) . "'
    652                 AND parent_id = '" . addslashes($parent_id) . "'
    653                 AND child_type = '" . addslashes($child_type) . "'
    654                 AND child_id = '" . addslashes($child_id) . "'
    655                 AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . addslashes($relationship_type) . "'") . "
     651                WHERE parent_type = '" . mysql_real_escape_string($parent_type) . "'
     652                AND parent_id = '" . mysql_real_escape_string($parent_id) . "'
     653                AND child_type = '" . mysql_real_escape_string($child_type) . "'
     654                AND child_id = '" . mysql_real_escape_string($child_id) . "'
     655                AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . mysql_real_escape_string($relationship_type) . "'") . "
    656656            ");
    657657        } else {
    658658            $qid = dbQuery("
    659659                SELECT 1 FROM node_tbl
    660                 WHERE child_type = '" . addslashes($child_type) . "'
    661                 AND child_id = '" . addslashes($child_id) . "'
     660                WHERE child_type = '" . mysql_real_escape_string($child_type) . "'
     661                AND child_id = '" . mysql_real_escape_string($child_id) . "'
    662662            ");
    663663        }
     
    781781        dbQuery("
    782782            UPDATE node_tbl
    783             SET subnode_quantity = subnode_quantity + '" . addslashes($num_children) . "'
    784             WHERE child_type = '" . addslashes($child_type) . "'
    785             AND child_id = '" . addslashes($child_id) . "'
     783            SET subnode_quantity = subnode_quantity + '" . mysql_real_escape_string($num_children) . "'
     784            WHERE child_type = '" . mysql_real_escape_string($child_type) . "'
     785            AND child_id = '" . mysql_real_escape_string($child_id) . "'
    786786        ",false);
    787787        $qid = dbQuery("
    788788            SELECT parent_type, parent_id
    789789            FROM node_tbl
    790             WHERE child_type = '" . addslashes($child_type) . "'
    791             AND child_id = '" . addslashes($child_id) . "'
     790            WHERE child_type = '" . mysql_real_escape_string($child_type) . "'
     791            AND child_id = '" . mysql_real_escape_string($child_id) . "'
    792792        ",false);
    793793        while ((list($parent_type, $parent_id) = mysql_fetch_row($qid)) && $parent_id > 0) {
  • branches/1.1dev/lib/OrderStatus.inc.php

    r81 r82  
    1818{
    1919    if ($status != '') {
    20         $whereclause = 'WHERE status = ' . addslashes($status);
     20        $whereclause = 'WHERE status = ' . mysql_real_escape_string($status);
    2121    } else {
    2222        $whereclause = '';
     
    5252    global $CFG, $_SESSION;
    5353
    54     $qid = dbQuery("SELECT status, email, first_name, last_name FROM order_tbl WHERE order_id = " . addslashes($order_id));
     54    $qid = dbQuery("SELECT status, email, first_name, last_name FROM order_tbl WHERE order_id = " . mysql_real_escape_string($order_id));
    5555    if (mysql_num_rows($qid) == 1) {
    5656    /* The order exists, we contine. */
     
    105105        /* Otherwise we assume everything was updated okay and that
    106106         * we have a valid new status and so proceed updating the orders table. */
    107         dbQuery("UPDATE order_tbl SET status = " . addslashes($db_update) . " WHERE order_id = " . addslashes($order_id));
     107        dbQuery("UPDATE order_tbl SET status = " . mysql_real_escape_string($db_update) . " WHERE order_id = " . mysql_real_escape_string($order_id));
    108108       
    109109        if ($email_user == true) {
     
    111111           
    112112            /* Query to load the details of this order. */
    113             $qid_order = dbQuery("SELECT * FROM order_tbl WHERE order_id = " . addslashes($order_id));
     113            $qid_order = dbQuery("SELECT * FROM order_tbl WHERE order_id = " . mysql_real_escape_string($order_id));
    114114            $order = mysql_fetch_assoc($qid_order);
    115115
     
    129129                LEFT JOIN product_tbl p
    130130                ON (oi.product_id = p.product_id)
    131                 WHERE oi.order_id = " . addslashes($order_id) . "
     131                WHERE oi.order_id = " . mysql_real_escape_string($order_id) . "
    132132            ");
    133133            $item_num = 0;
     
    214214
    215215    if ($polarity == '+' || $polarity == '-') {
    216         $qid = dbQuery("SELECT product_id, qty as order_qty FROM order_items_tbl WHERE order_id = " . addslashes($order_id));
     216        $qid = dbQuery("SELECT product_id, qty as order_qty FROM order_items_tbl WHERE order_id = " . mysql_real_escape_string($order_id));
    217217        /* First we make sure each item is in stock in adequate quantities. */
    218218        while ($order_item = mysql_fetch_assoc($qid)) {
  • branches/1.1dev/lib/PageNumbers.inc.php

    r81 r82  
    197197    {
    198198        if (is_numeric($this->first_item) && is_numeric($this->_per_page)) {
    199             return ' LIMIT ' . addslashes($this->first_item) . ', ' . addslashes($this->_per_page) . ' ';
     199            return ' LIMIT ' . mysql_real_escape_string($this->first_item) . ', ' . mysql_real_escape_string($this->_per_page) . ' ';
    200200        } else {
    201201            logMsg(sprintf('Could not find SQL to LIMIT by %s %s.', $this->first_item, $this->_per_page), LOG_WARNING, __FILE__, __LINE__);
  • branches/1.1dev/lib/RecordLock.inc.php

    r81 r82  
    4545            $qid = dbQuery("
    4646                SELECT * FROM lock_tbl
    47                 WHERE lock_id = '" . addslashes($record_table_or_lock_id) . "'
     47                WHERE lock_id = '" . mysql_real_escape_string($record_table_or_lock_id) . "'
    4848            ");
    4949        } else {
     
    5151            $qid = dbQuery("
    5252                SELECT * FROM lock_tbl
    53                 WHERE record_table = '" . addslashes($record_table_or_lock_id) . "'
    54                 AND record_key = '" . addslashes($record_key) . "'
    55                 AND record_val = '" . addslashes($record_val) . "'
     53                WHERE record_table = '" . mysql_real_escape_string($record_table_or_lock_id) . "'
     54                AND record_key = '" . mysql_real_escape_string($record_key) . "'
     55                AND record_val = '" . mysql_real_escape_string($record_val) . "'
    5656            ");
    5757        }
    5858        if ($this->data = mysql_fetch_assoc($qid)) {
    5959            // This could be integrated into the above query, but with the new auth system, this will be a $auth-> method call.
    60 //             $qid = dbQuery("SELECT username FROM admin_tbl WHERE admin_id = '" . addslashes($this->data['set_by_admin_id']) . "'");
     60//             $qid = dbQuery("SELECT username FROM admin_tbl WHERE admin_id = '" . mysql_real_escape_string($this->data['set_by_admin_id']) . "'");
    6161//             list($this->data['editor']) = mysql_fetch_row($qid);
    6262            $this->data['editor'] = $this->_auth->getUsername($this->data['set_by_admin_id']);
     
    8686    {
    8787        if (isset($this->data['lock_id'])) {
    88             $qid = dbQuery("SELECT * FROM lock_tbl WHERE lock_id = '" . addslashes($this->data['lock_id']) . "'");
     88            $qid = dbQuery("SELECT * FROM lock_tbl WHERE lock_id = '" . mysql_real_escape_string($this->data['lock_id']) . "'");
    8989            if ($lock = mysql_fetch_assoc($qid)) {
    9090                return ($lock['set_by_admin_id'] == $this->_auth->getVal('user_id'));
     
    112112        dbQuery("
    113113            DELETE FROM lock_tbl
    114             WHERE record_table = '" . addslashes($record_table) . "'
    115             AND record_key = '" . addslashes($record_key) . "'
    116             AND record_val = '" . addslashes($record_val) . "'
     114            WHERE record_table = '" . mysql_real_escape_string($record_table) . "'
     115            AND record_key = '" . mysql_real_escape_string($record_key) . "'
     116            AND record_val = '" . mysql_real_escape_string($record_val) . "'
    117117        ");
    118118       
     
    127127                lock_datetime
    128128            ) VALUES (
    129                 '" . addslashes($record_table) . "',
    130                 '" . addslashes($record_key) . "',
    131                 '" . addslashes($record_val) . "',
    132                 '" . addslashes($title) . "',
    133                 '" . addslashes($this->_auth->getVal('user_id')) . "',
     129                '" . mysql_real_escape_string($record_table) . "',
     130                '" . mysql_real_escape_string($record_key) . "',
     131                '" . mysql_real_escape_string($record_val) . "',
     132                '" . mysql_real_escape_string($title) . "',
     133                '" . mysql_real_escape_string($this->_auth->getVal('user_id')) . "',
    134134                NOW()
    135135            )
     
    151151        dbQuery("
    152152            DELETE FROM lock_tbl
    153             WHERE lock_id = '" . addslashes($this->data['lock_id']) . "'
     153            WHERE lock_id = '" . mysql_real_escape_string($this->data['lock_id']) . "'
    154154        ");
    155155    }
     
    162162        if (isset($user_id)) {
    163163            // Delete specific user's locks.
    164             dbQuery("DELETE FROM lock_tbl WHERE set_by_admin_id = '" . addslashes($user_id) . "'");
     164            dbQuery("DELETE FROM lock_tbl WHERE set_by_admin_id = '" . mysql_real_escape_string($user_id) . "'");
    165165            logMsg(sprintf('Record locks owned by %s %s have been deleted', $this->_auth->getVal('auth_name'), $this->_auth->getUsername($user_id)), LOG_INFO, __FILE__, __LINE__);
    166166        } else {
  • branches/1.1dev/lib/SortOrder.inc.php

    r81 r82  
    149149
    150150        if (!empty($this->_columns[strtolower($this->sort_by)][strtolower(strtolower($this->order))])) {
    151             return ' ORDER BY ' . addslashes($this->_columns[strtolower($this->sort_by)][strtolower(strtolower($this->order))]);
     151            return ' ORDER BY ' . mysql_real_escape_string($this->_columns[strtolower($this->sort_by)][strtolower(strtolower($this->order))]);
    152152        } else {
    153153            logMsg(sprintf('Could not find SQL to sort by %s %s.', $this->sort_by, $this->order), LOG_WARNING, __FILE__, __LINE__);
  • branches/1.1dev/lib/Utilities.inc.php

    r81 r82  
    487487{
    488488    if (is_array($array) && !empty($array)) {
    489         return join(',', array_map('addslashes', array_keys($array)));
     489        return join(',', array_map('mysql_real_escape_string', array_keys($array)));
    490490    }
    491491}
Note: See TracChangeset for help on using the changeset viewer.