Changeset 2765


Ignore:
Timestamp:
Oct 17, 2008, 3:06:00 AM (16 years ago)
Author:
rvelices
Message:
  • mysql potential injection paranoia + code compaction in common.inc.php
Location:
branches/2.0/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0/include/common.inc.php

    r2700 r2765  
    3737if( !get_magic_quotes_gpc() )
    3838{
     39  function sanitize_mysql_kv(&$v, $k)
     40  {
     41    $v = addslashes($v);
     42  }
    3943  if( is_array( $_GET ) )
    4044  {
    41     while( list($k, $v) = each($_GET) )
    42     {
    43       if( is_array($_GET[$k]) )
    44       {
    45         while( list($k2, $v2) = each($_GET[$k]) )
    46         {
    47           $_GET[$k][$k2] = addslashes($v2);
    48         }
    49         @reset($_GET[$k]);
    50       }
    51       else
    52       {
    53         $_GET[$k] = addslashes($v);
    54       }
    55     }
    56     @reset($_GET);
    57   }
    58 
    59   if( is_array($_POST) )
    60   {
    61     while( list($k, $v) = each($_POST) )
    62     {
    63       if( is_array($_POST[$k]) )
    64       {
    65         while( list($k2, $v2) = each($_POST[$k]) )
    66         {
    67           $_POST[$k][$k2] = addslashes($v2);
    68         }
    69         @reset($_POST[$k]);
    70       }
    71       else
    72       {
    73         $_POST[$k] = addslashes($v);
    74       }
    75     }
    76     @reset($_POST);
    77   }
    78 
    79   if( is_array($_COOKIE) )
    80   {
    81     while( list($k, $v) = each($_COOKIE) )
    82     {
    83       if( is_array($_COOKIE[$k]) )
    84       {
    85         while( list($k2, $v2) = each($_COOKIE[$k]) )
    86         {
    87           $_COOKIE[$k][$k2] = addslashes($v2);
    88         }
    89         @reset($_COOKIE[$k]);
    90       }
    91       else
    92       {
    93         $_COOKIE[$k] = addslashes($v);
    94       }
    95     }
    96     @reset($_COOKIE);
     45    array_walk_recursive( $_GET, 'sanitize_mysql_kv' );
     46  }
     47  if( is_array( $_POST ) )
     48  {
     49    array_walk_recursive( $_POST, 'sanitize_mysql_kv' );
     50  }
     51  if( is_array( $_COOKIE ) )
     52  {
     53    array_walk_recursive( $_COOKIE, 'sanitize_mysql_kv' );
    9754  }
    9855}
  • branches/2.0/include/ws_functions.inc.php

    r2756 r2765  
    188188    return new PwgError(401, 'Access denied');
    189189  }
     190  $params['image_id'] = array_map( 'intval',$params['image_id'] );
    190191  if ( empty($params['image_id']) )
    191192  {
     
    292293GROUP BY i.id
    293294'.$order_by.'
    294 LIMIT '.$params['per_page']*$params['page'].','.$params['per_page'];
     295LIMIT '.(int)($params['per_page']*$params['page']).','.(int)$params['per_page'];
    295296
    296297    $result = pwg_query($query);
     
    684685  WHERE '.$where_comments.'
    685686  ORDER BY date
    686   LIMIT '.$params['comments_per_page']*(int)$params['comments_page'].
    687     ','.$params['comments_per_page'];
     687  LIMIT '.(int)($params['comments_per_page']*$params['comments_page']).
     688    ','.(int)$params['comments_per_page'];
    688689
    689690    $result = pwg_query($query);
     
    858859    return new PwgError(401, 'Access denied');
    859860  }
     861  $params['image_id'] = array_map( 'intval',$params['image_id'] );
    860862  if ( empty($params['image_id']) )
    861863  {
     
    12631265    AND ', $where_clauses).'
    12641266'.$order_by.'
    1265 LIMIT '.$params['per_page']*$params['page'].','.$params['per_page'];
     1267LIMIT '.(int)($params['per_page']*$params['page']).','.(int)$params['per_page'];
    12661268
    12671269    $result = pwg_query($query);
Note: See TracChangeset for help on using the changeset viewer.