Changeset 86df152 in github


Ignore:
Timestamp:
Dec 29, 2006 4:06:39 PM (6 years ago)
Author:
thomascube <thomas@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
e93a2d7
Parents:
3b12aee
Message:

Error handling for attachment uploads; multibyte-safe string functions; XSS improvements

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    ree883ad r86df152  
    11CHANGELOG RoundCube Webmail 
    22--------------------------- 
     3 
     42006/12/29 (thomasb) 
     5---------- 
     6- Added error handling for attachment uploads 
     7- Use multibyte safe string functions where necessary (closes #1483988) 
     8- Updated Swiss German localization (de_CH) 
     9 
    310 
    4112006/12/22 (thomasb) 
  • program/include/main.inc

    ree883ad r86df152  
    401401function rcmail_set_locale($lang) 
    402402  { 
    403   global $OUTPUT, $MBSTRING; 
     403  global $OUTPUT, $CHARSET, $MBSTRING; 
    404404  static $s_mbstring_loaded = NULL; 
    405405   
     
    409409  else 
    410410    $MBSTRING = $s_mbstring_loaded = FALSE; 
     411     
     412  if ($MBSTRING) 
     413    mb_internal_encoding($CHARSET); 
    411414 
    412415  $OUTPUT->set_charset(rcube_language_prop($lang, 'charset')); 
  • program/include/rcube_shared.inc

    r2bca6e1 r86df152  
    66 |                                                                       | 
    77 | This file is part of the RoundCube PHP suite                          | 
    8  | Copyright (C) 2005, RoundCube Dev. - Switzerland                      | 
     8 | Copyright (C) 2005-2006, RoundCube Dev. - Switzerland                 | 
    99 | Licensed under the GNU GPL                                            | 
    1010 |                                                                       | 
     
    130130     
    131131    // set default page title 
    132     if (!strlen($this->title)) 
     132    if (empty($this->title)) 
    133133      $this->title = 'RoundCube Mail'; 
    134134   
     
    159159   } 
    160160 
    161     if (strlen($this->scripts['head'])) 
     161    if (!empty($this->scripts['head'])) 
    162162      $__page_header .= sprintf($this->script_tag, $this->scripts['head']); 
    163163           
     
    168168      } 
    169169 
    170     if (strlen($this->scripts['foot'])) 
     170    if (!empty($this->scripts['foot'])) 
    171171      $__page_footer .= sprintf($this->script_tag, $this->scripts['foot']); 
    172172       
     
    177177   
    178178    // find page header 
    179     if($hpos = strpos(strtolower($output), '</head>')) 
     179    if($hpos = rc_strpos(rc_strtolower($output), '</head>')) 
    180180      $__page_header .= "\n"; 
    181181    else  
    182182      { 
    183183      if (!is_numeric($hpos)) 
    184         $hpos = strpos(strtolower($output), '<body'); 
    185       if (!is_numeric($hpos) && ($hpos = strpos(strtolower($output), '<html'))) 
     184        $hpos = rc_strpos(rc_strtolower($output), '<body'); 
     185      if (!is_numeric($hpos) && ($hpos = rc_strpos(rc_strtolower($output), '<html'))) 
    186186        { 
    187187        while($output[$hpos]!='>') 
     
    195195    // add page hader 
    196196    if($hpos) 
    197       $output = substr($output,0,$hpos) . $__page_header . substr($output,$hpos,strlen($output)); 
     197      $output = rc_substr($output,0,$hpos) . $__page_header . rc_substr($output,$hpos,rc_strlen($output)); 
    198198    else 
    199199      $output = $__page_header . $output; 
     
    201201   
    202202    // find page body 
    203     if($bpos = strpos(strtolower($output), '<body')) 
     203    if($bpos = rc_strpos(rc_strtolower($output), '<body')) 
    204204      { 
    205205      while($output[$bpos]!='>') $bpos++; 
     
    207207      } 
    208208    else 
    209       $bpos = strpos(strtolower($output), '</head>')+7; 
     209      $bpos = rc_strpos(rc_strtolower($output), '</head>')+7; 
    210210   
    211211    // add page body 
    212212    if($bpos && $__page_body) 
    213       $output = substr($output,0,$bpos) . "\n$__page_body\n" . substr($output,$bpos,strlen($output)); 
     213      $output = rc_substr($output,0,$bpos) . "\n$__page_body\n" . rc_substr($output,$bpos,rc_strlen($output)); 
    214214   
    215215   
    216216    // find and add page footer 
    217     $output_lc = strtolower($output); 
     217    $output_lc = rc_strtolower($output); 
    218218    if(($fpos = strrstr($output_lc, '</body>')) || 
    219219       ($fpos = strrstr($output_lc, '</html>'))) 
    220       $output = substr($output,0,$fpos) . "$__page_footer\n" . substr($output,$fpos); 
     220      $output = rc_substr($output,0,$fpos) . "$__page_footer\n" . rc_substr($output,$fpos); 
    221221    else 
    222222      $output .= "\n$__page_footer"; 
     
    879879      unset($this->attrib['value']); 
    880880 
    881     if (strlen($value) && !isset($this->attrib['mce_editable'])) 
     881    if (!empty($value) && !isset($this->attrib['mce_editable'])) 
    882882      $value = Q($value, 'strict', FALSE); 
    883883 
     
    10131013    foreach ($this->options as $option) 
    10141014      { 
    1015       $selected = ((strlen($option['value']) && in_array($option['value'], $select, TRUE)) || 
     1015      $selected = ((!empty($option['value']) && in_array($option['value'], $select, TRUE)) || 
    10161016                   (in_array($option['text'], $select, TRUE))) ? $this->_conv_case(' selected', 'attrib') : ''; 
    10171017                   
    10181018      $options_str .= sprintf("<%s%s%s>%s</%s>\n", 
    10191019                             $this->_conv_case('option', 'tag'), 
    1020                              strlen($option['value']) ? sprintf($value_str, $option['value']) : '', 
     1020                             !empty($option['value']) ? sprintf($value_str, $option['value']) : '', 
    10211021                             $selected,  
    10221022                             Q($option['text'], 'strict', FALSE), 
     
    11051105  $vars = isset($attrib['vars']) ? $attrib['vars'] : ''; 
    11061106 
    1107   $command_name = strlen($attrib['command']) ? $attrib['command'] : NULL; 
     1107  $command_name = !empty($attrib['command']) ? $attrib['command'] : NULL; 
    11081108  $alias = $attrib['name'] ? $attrib['name'] : ($command_name && $command_label_map[$command_name] ? $command_label_map[$command_name] : ''); 
    11091109 
     
    12781278            $value = $value ? "true" : "false"; 
    12791279            } 
    1280           else if ((($type=='mixed' && is_numeric($value)) || $type=='int') && strlen($value)<16)   // js interprets numbers with digits >15 as ...e+...  
     1280          else if ((($type=='mixed' && is_numeric($value)) || $type=='int') && rc_strlen($value)<16)   // js interprets numbers with digits >15 as ...e+...  
    12811281            $is_string = FALSE; 
    12821282          else 
     
    13351335 
    13361336 
     1337// parse a human readable string for a number of bytes 
     1338function parse_bytes($str) 
     1339  { 
     1340  if (is_numeric($str)) 
     1341    return intval($str); 
     1342     
     1343  if (preg_match('/([0-9]+)([a-z])/i', $str, $regs)) 
     1344    { 
     1345      $bytes = floatval($regs[1]); 
     1346      switch (strtolower($regs[2])) 
     1347      { 
     1348        case 'g': 
     1349          $bytes *= 1073741824; 
     1350          break; 
     1351        case 'm': 
     1352          $bytes *= 1048576; 
     1353          break; 
     1354        case 'k': 
     1355          $bytes *= 1024; 
     1356          break; 
     1357      } 
     1358    } 
     1359 
     1360  return intval($bytes); 
     1361  } 
     1362     
    13371363// create a human readable string for a number of bytes 
    13381364function show_bytes($bytes) 
     
    13941420 
    13951421 
     1422// wrapper function for strlen 
     1423function rc_strlen($str) 
     1424  { 
     1425    if (function_exists('mb_strlen')) 
     1426      return mb_strlen($str); 
     1427    else 
     1428      return strlen($str); 
     1429  } 
     1430   
     1431// wrapper function for strtolower 
     1432function rc_strtolower($str) 
     1433  { 
     1434    if (function_exists('mb_strtolower')) 
     1435      return mb_strtolower($str); 
     1436    else 
     1437      return strtolower($str); 
     1438  } 
     1439 
     1440// wrapper function for substr 
     1441function rc_substr($str, $start, $len) 
     1442  { 
     1443  if (function_exists('mb_substr')) 
     1444    return mb_substr($str, $start, $len); 
     1445  else 
     1446    return substr($str, $start, $len); 
     1447  } 
     1448 
     1449// wrapper function for strpos 
     1450function rc_strpos($haystack, $needle, $offset=0) 
     1451  { 
     1452  if (function_exists('mb_strpos')) 
     1453    return mb_strpos($haystack, $needle, $offset); 
     1454  else 
     1455    return strpos($haystack, $needle, $offset); 
     1456  } 
     1457 
     1458// wrapper function for strrpos 
     1459function rc_strrpos($haystack, $needle, $offset=0) 
     1460  { 
     1461  if (function_exists('mb_strrpos')) 
     1462    return mb_strrpos($haystack, $needle, $offset); 
     1463  else 
     1464    return strrpos($haystack, $needle, $offset); 
     1465  } 
     1466 
     1467 
    13961468// replace the middle part of a string with ... 
    13971469// if it is longer than the allowed length 
    13981470function abbrevate_string($str, $maxlength, $place_holder='...') 
    13991471  { 
    1400   $length = strlen($str); 
    1401   $first_part_length = floor($maxlength/2) - strlen($place_holder); 
     1472  $length = rc_strlen($str); 
     1473  $first_part_length = floor($maxlength/2) - rc_strlen($place_holder); 
    14021474   
    14031475  if ($length > $maxlength) 
    14041476    { 
    14051477    $second_starting_location = $length - $maxlength + $first_part_length + 1; 
    1406     $str = substr($str, 0, $first_part_length) . $place_holder . substr($str, $second_starting_location, $length); 
     1478    $str = rc_substr($str, 0, $first_part_length) . $place_holder . rc_substr($str, $second_starting_location, $length); 
    14071479    } 
    14081480 
  • program/localization/de_CH/labels.inc

    r421f5e3 r86df152  
    133133$labels['addattachment']  = 'Datei anfÃŒgen'; 
    134134$labels['charset']  = 'Zeichensatz'; 
     135$labels['editortype'] = 'Editor-Typ'; 
    135136$labels['returnreceipt'] = 'EmpfangsbestÀtigung'; 
    136137 
     
    151152$labels['nosubject']  = '(kein Betreff)'; 
    152153$labels['showimages'] = 'Bilder anzeigen'; 
     154 
     155$labels['htmltoggle'] = 'HTML'; 
     156$labels['plaintoggle'] = 'Klartext'; 
    153157 
    154158 
     
    175179 
    176180$labels['previouspage']   = 'Eine Seite zurÃŒck'; 
     181$labels['firstpage']      = 'Erste Seite'; 
    177182$labels['nextpage']       = 'NÀchste Seite'; 
     183$labels['lastpage']      = 'Letzte Seite'; 
    178184 
    179185// LDAP search 
  • program/localization/de_CH/messages.inc

    rb190970 r86df152  
    6767$messages['deletecontactconfirm']  = 'Wollen Sie die ausgewÀhlten Kontakte wirklich löschen'; 
    6868 
     69$messages['deletemessagesconfirm'] = 'Wollen Sie die ausgewÀhlten Nachrichten wirklich löschen?'; 
     70 
    6971$messages['deletefolderconfirm']  = 'Wollen Sie diesen Ordner wirklich löschen?'; 
    7072 
     
    111113$messages['messageopenerror'] = 'Die Nachricht konnte nicht vom Server geladen werden'; 
    112114 
     115$messages['fileuploaderror'] = 'Der Dateiupload ist fehlgeschlagen'; 
     116 
     117$messages['filesizeerror'] = 'Die Datei ÃŒberschreitet die maximale Grösse von $size'; 
     118 
    113119?> 
  • program/localization/en_US/messages.inc

    rb190970 r86df152  
    115115$messages['messageopenerror'] = 'Could not load message from server'; 
    116116 
     117$messages['fileuploaderror'] = 'File upload failed'; 
     118 
     119$messages['filesizeerror'] = 'The uploaded file exceeds the maximum size of $size'; 
     120 
    117121?> 
  • program/steps/mail/compose.inc

    r2bca6e1 r86df152  
    4747$MESSAGE = NULL; 
    4848 
    49 // nothing below is called during message composition, only at "new/forward/reply/draft" initialization 
    50 // since there are many ways to leave the compose page improperly, it seems necessary to clean-up an old 
     49// Nothing below is called during message composition, only at "new/forward/reply/draft" initialization or 
     50// if a compose-ID is given (i.e. when the compose step is opened in a new window/tab). 
     51// Since there are many ways to leave the compose page improperly, it seems necessary to clean-up an old 
    5152// compose when a "new/forward/reply/draft" is called - otherwise the old session attachments will appear 
    5253 
    53 rcmail_compose_cleanup(); 
    54 $_SESSION['compose'] = array('id' => uniqid(rand())); 
     54if (!is_array($_SESSION['compose']) || $_SESSION['compose']['id'] != get_input_value('_id', RCUBE_INPUT_GET)) 
     55  { 
     56  rcmail_compose_cleanup(); 
     57  $_SESSION['compose'] = array('id' => uniqid(rand())); 
     58  } 
    5559 
    5660// add some labels to client 
  • program/steps/mail/func.inc

    r3b12aee r86df152  
    12151215    { 
    12161216    $prev_body = $body; 
    1217     $body = preg_replace('/(<[^!][^>]*?\s)(on\w+?)(=[^>]*?>)/im', '$1__removed=$3', $body); 
     1217    $body = preg_replace('/(<[^!][^>]*?\s)(on[^=]+)(=[^>]*?>)/im', '$1__removed=$3', $body); 
    12181218    $body = preg_replace('/(<[^!][^>]*?\shref=["\']?)(javascript:)([^>]*?>)/im', '$1null:$3', $body); 
    12191219    } 
  • program/steps/mail/upload.inc

    rf91a499 r86df152  
    6666                         $content); 
    6767    } 
     68  else // upload failed 
     69    { 
     70    $err = $_FILES['_attachments']['error'][$i]; 
     71    if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) 
     72      $msg = rcube_label(array('name' => 'filesizeerror', 'vars' => array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize')))))); 
     73    else 
     74      $msg = rcube_label('fileuploaderror'); 
     75     
     76    $response = sprintf("parent.%s.display_message('%s', 'error');", $JS_OBJECT_NAME, JQ($msg)); 
     77    } 
    6878  } 
    6979 
Note: See TracChangeset for help on using the changeset viewer.