Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 09a7904

Browse files
committed
[UPD] CodeIgniter 3.1.8
1 parent 51dcc41 commit 09a7904

9 files changed

Lines changed: 81 additions & 39 deletions

File tree

system/core/CodeIgniter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
* @var string
5656
*
5757
*/
58-
const CI_VERSION = '3.1.7';
58+
const CI_VERSION = '3.1.8';
5959

6060
/*
6161
* ------------------------------------------------------

system/core/Security.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ class CI_Security {
134134
*/
135135
protected $_never_allowed_str = array(
136136
'document.cookie' => '[removed]',
137+
'(document).cookie' => '[removed]',
137138
'document.write' => '[removed]',
139+
'(document).write' => '[removed]',
138140
'.parentNode' => '[removed]',
139141
'.innerHTML' => '[removed]',
140142
'-moz-binding' => '[removed]',
@@ -152,7 +154,7 @@ class CI_Security {
152154
*/
153155
protected $_never_allowed_regex = array(
154156
'javascript\s*:',
155-
'(document|(document\.)?window)\.(location|on\w*)',
157+
'(\(?document\)?|\(?window\)?(\.document)?)\.(location|on\w*)',
156158
'expression\s*(\(|&\#40;)', // CSS and IE
157159
'vbscript\s*:', // IE, surprise!
158160
'wscript\s*:', // IE
@@ -542,6 +544,14 @@ public function xss_clean($str, $is_image = FALSE)
542544
$str
543545
);
544546

547+
// Same thing, but for "tag functions" (e.g. eval`some code`)
548+
// See https://github.com/bcit-ci/CodeIgniter/issues/5420
549+
$str = preg_replace(
550+
'#(alert|prompt|confirm|cmd|passthru|eval|exec|expression|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)`(.*?)`#si',
551+
'\\1\\2`\\3`',
552+
$str
553+
);
554+
545555
// Final clean up
546556
// This adds a bit of extra precaution in case
547557
// something got through the above filters
@@ -853,7 +863,7 @@ protected function _sanitize_naughty_html($matches)
853863
// For other tags, see if their attributes are "evil" and strip those
854864
elseif (isset($matches['attributes']))
855865
{
856-
// We'll store the already fitlered attributes here
866+
// We'll store the already filtered attributes here
857867
$attributes = array();
858868

859869
// Attribute-catching pattern
@@ -927,7 +937,7 @@ protected function _js_link_removal($match)
927937
return str_replace(
928938
$match[1],
929939
preg_replace(
930-
'#href=.*?(?:(?:alert|prompt|confirm)(?:\(|&\#40;)|javascript:|livescript:|mocha:|charset=|window\.|document\.|\.cookie|<script|<xss|d\s*a\s*t\s*a\s*:)#si',
940+
'#href=.*?(?:(?:alert|prompt|confirm)(?:\(|&\#40;|`|&\#96;)|javascript:|livescript:|mocha:|charset=|window\.|\(?document\)?\.|\.cookie|<script|<xss|d\s*a\s*t\s*a\s*:)#si',
931941
'',
932942
$this->_filter_attributes($match[1])
933943
),
@@ -955,7 +965,7 @@ protected function _js_img_removal($match)
955965
return str_replace(
956966
$match[1],
957967
preg_replace(
958-
'#src=.*?(?:(?:alert|prompt|confirm|eval)(?:\(|&\#40;)|javascript:|livescript:|mocha:|charset=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)#si',
968+
'#src=.*?(?:(?:alert|prompt|confirm|eval)(?:\(|&\#40;|`|&\#96;)|javascript:|livescript:|mocha:|charset=|window\.|\(?document\)?\.|\.cookie|<script|<xss|base64\s*,)#si',
959969
'',
960970
$this->_filter_attributes($match[1])
961971
),

system/database/DB_query_builder.php

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ protected function _wh($qb_key, $key, $value = NULL, $type = 'AND ', $escape = N
680680
{
681681
if ($escape === TRUE)
682682
{
683-
$v = ' '.$this->escape($v);
683+
$v = $this->escape($v);
684684
}
685685

686686
if ( ! $this->_has_operator($k))
@@ -698,10 +698,11 @@ protected function _wh($qb_key, $key, $value = NULL, $type = 'AND ', $escape = N
698698
$k = substr($k, 0, $match[0][1]).($match[1][0] === '=' ? ' IS NULL' : ' IS NOT NULL');
699699
}
700700

701-
$this->{$qb_key}[] = array('condition' => $prefix.$k.$v, 'escape' => $escape);
701+
${$qb_key} = array('condition' => $prefix.$k, 'value' => $v, 'escape' => $escape);
702+
$this->{$qb_key}[] = ${$qb_key};
702703
if ($this->qb_caching === TRUE)
703704
{
704-
$this->{$qb_cache_key}[] = array('condition' => $prefix.$k.$v, 'escape' => $escape);
705+
$this->{$qb_cache_key}[] = ${$qb_key};
705706
$this->qb_cache_exists[] = substr($qb_key, 3);
706707
}
707708

@@ -834,6 +835,7 @@ protected function _where_in($key = NULL, $values = NULL, $not = FALSE, $type =
834835

835836
$where_in = array(
836837
'condition' => $prefix.$key.$not.' IN('.implode(', ', $where_in).')',
838+
'value' => NULL,
837839
'escape' => $escape
838840
);
839841

@@ -962,33 +964,34 @@ protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $n
962964
$v = $this->escape_like_str($v);
963965
}
964966

965-
if ($side === 'none')
967+
switch ($side)
966968
{
967-
$like_statement = "{$prefix} {$k} {$not} LIKE '{$v}'";
968-
}
969-
elseif ($side === 'before')
970-
{
971-
$like_statement = "{$prefix} {$k} {$not} LIKE '%{$v}'";
972-
}
973-
elseif ($side === 'after')
974-
{
975-
$like_statement = "{$prefix} {$k} {$not} LIKE '{$v}%'";
976-
}
977-
else
978-
{
979-
$like_statement = "{$prefix} {$k} {$not} LIKE '%{$v}%'";
969+
case 'none':
970+
$v = "'{$v}'";
971+
break;
972+
case 'before':
973+
$v = "%'{$v}'";
974+
break;
975+
case 'after':
976+
$v = "'{$v}%'";
977+
break;
978+
case 'both':
979+
default:
980+
$v = "'%{$v}%'";
981+
break;
980982
}
981983

982984
// some platforms require an escape sequence definition for LIKE wildcards
983985
if ($escape === TRUE && $this->_like_escape_str !== '')
984986
{
985-
$like_statement .= sprintf($this->_like_escape_str, $this->_like_escape_chr);
987+
$v .= sprintf($this->_like_escape_str, $this->_like_escape_chr);
986988
}
987989

988-
$this->qb_where[] = array('condition' => $like_statement, 'escape' => $escape);
990+
$qb_where = array('condition' => "{$prefix} {$k} {$not} LIKE", 'value' => $v, 'escape' => $escape);
991+
$this->qb_where[] = $qb_where;
989992
if ($this->qb_caching === TRUE)
990993
{
991-
$this->qb_cache_where[] = array('condition' => $like_statement, 'escape' => $escape);
994+
$this->qb_cache_where[] = $qb_where;
992995
$this->qb_cache_exists[] = 'where';
993996
}
994997
}
@@ -1013,6 +1016,7 @@ public function group_start($not = '', $type = 'AND ')
10131016
$prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) ? '' : $type;
10141017
$where = array(
10151018
'condition' => $prefix.$not.str_repeat(' ', ++$this->qb_where_group_count).' (',
1019+
'value' => NULL,
10161020
'escape' => FALSE
10171021
);
10181022

@@ -1073,6 +1077,7 @@ public function group_end()
10731077
$this->qb_where_group_started = FALSE;
10741078
$where = array(
10751079
'condition' => str_repeat(' ', $this->qb_where_group_count--).')',
1080+
'value' => NULL,
10761081
'escape' => FALSE
10771082
);
10781083

@@ -1433,7 +1438,7 @@ public function count_all_results($table = '', $reset = TRUE)
14331438
// --------------------------------------------------------------------
14341439

14351440
/**
1436-
* Get_Where
1441+
* get_where()
14371442
*
14381443
* Allows the where clause, limit and offset to be added directly
14391444
*
@@ -2395,7 +2400,7 @@ protected function _compile_wh($qb_key)
23952400
}
23962401
elseif ($this->{$qb_key}[$i]['escape'] === FALSE)
23972402
{
2398-
$this->{$qb_key}[$i] = $this->{$qb_key}[$i]['condition'];
2403+
$this->{$qb_key}[$i] = $this->{$qb_key}[$i]['condition'].(isset($this->{$qb_key}[$i]['value']) ? ' '.$this->{$qb_key}[$i]['value'] : '');
23992404
continue;
24002405
}
24012406

@@ -2434,7 +2439,7 @@ protected function _compile_wh($qb_key)
24342439
.' '.trim($matches[3]).$matches[4].$matches[5];
24352440
}
24362441

2437-
$this->{$qb_key}[$i] = implode('', $conditions);
2442+
$this->{$qb_key}[$i] = implode('', $conditions).(isset($this->{$qb_key}[$i]['value']) ? ' '.$this->{$qb_key}[$i]['value'] : '');
24382443
}
24392444

24402445
return ($qb_key === 'qb_having' ? "\nHAVING " : "\nWHERE ")

system/database/drivers/oci8/oci8_driver.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class CI_DB_oci8_driver extends CI_DB {
9797
*
9898
* @var bool
9999
*/
100-
public $limit_used;
100+
public $limit_used = FALSE;
101101

102102
// --------------------------------------------------------------------
103103

@@ -685,4 +685,17 @@ protected function _close()
685685
oci_close($this->conn_id);
686686
}
687687

688+
// --------------------------------------------------------------------
689+
690+
/**
691+
* We need to reset our $limit_used hack flag, so it doesn't propagate
692+
* to subsequent queries.
693+
*
694+
* @return void
695+
*/
696+
protected function _reset_select()
697+
{
698+
$this->limit_used = FALSE;
699+
parent::_reset_select();
700+
}
688701
}

system/database/drivers/postgre/postgre_driver.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ public function version()
224224
* and so we'll have to fall back to running a query in
225225
* order to get it.
226226
*/
227-
return isset($pg_version['server'])
228-
? $this->data_cache['version'] = $pg_version['server']
227+
return (isset($pg_version['server']) && preg_match('#^(\d+\.\d+)#', $pg_version['server'], $match))
228+
? $this->data_cache['version'] = $match[1]
229229
: parent::version();
230230
}
231231

@@ -354,8 +354,7 @@ public function affected_rows()
354354
*/
355355
public function insert_id()
356356
{
357-
$v = pg_version($this->conn_id);
358-
$v = isset($v['server']) ? $v['server'] : 0; // 'server' key is only available since PosgreSQL 7.4
357+
$v = $this->version();
359358

360359
$table = (func_num_args() > 0) ? func_get_arg(0) : NULL;
361360
$column = (func_num_args() > 1) ? func_get_arg(1) : NULL;

system/libraries/Email.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ public function valid_email($email)
10351035
if (function_exists('idn_to_ascii') && strpos($email, '@'))
10361036
{
10371037
list($account, $domain) = explode('@', $email, 2);
1038-
$domain = is_php('5.4')
1038+
$domain = defined('INTL_IDNA_VARIANT_UTS46')
10391039
? idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46)
10401040
: idn_to_ascii($domain);
10411041
$email = $account.'@'.$domain;
@@ -1856,7 +1856,7 @@ protected function _validate_email_for_shell(&$email)
18561856
if (function_exists('idn_to_ascii') && strpos($email, '@'))
18571857
{
18581858
list($account, $domain) = explode('@', $email, 2);
1859-
$domain = is_php('5.4')
1859+
$domain = defined('INTL_IDNA_VARIANT_UTS46')
18601860
? idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46)
18611861
: idn_to_ascii($domain);
18621862
$email = $account.'@'.$domain;
@@ -2074,7 +2074,19 @@ protected function _smtp_connect()
20742074
$this->_send_command('hello');
20752075
$this->_send_command('starttls');
20762076

2077-
$crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT);
2077+
/**
2078+
* STREAM_CRYPTO_METHOD_TLS_CLIENT is quite the mess ...
2079+
*
2080+
* - On PHP <5.6 it doesn't even mean TLS, but SSL 2.0, and there's no option to use actual TLS
2081+
* - On PHP 5.6.0-5.6.6, >=7.2 it means negotiation with any of TLS 1.0, 1.1, 1.2
2082+
* - On PHP 5.6.7-7.1.* it means only TLS 1.0
2083+
*
2084+
* We want the negotiation, so we'll force it below ...
2085+
*/
2086+
$method = is_php('5.6')
2087+
? STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
2088+
: STREAM_CRYPTO_METHOD_TLS_CLIENT;
2089+
$crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, $method);
20782090

20792091
if ($crypto !== TRUE)
20802092
{

system/libraries/Form_validation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ public function valid_email($str)
12311231
{
12321232
if (function_exists('idn_to_ascii') && preg_match('#\A([^@]+)@(.+)\z#', $str, $matches))
12331233
{
1234-
$domain = is_php('5.4')
1234+
$domain = defined('INTL_IDNA_VARIANT_UTS46')
12351235
? idn_to_ascii($matches[2], 0, INTL_IDNA_VARIANT_UTS46)
12361236
: idn_to_ascii($matches[2]);
12371237
$str = $matches[1].'@'.$domain;

system/libraries/Image_lib.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,10 @@ public function image_process_gd($action = 'resize')
835835
imagedestroy($dst_img);
836836
imagedestroy($src_img);
837837

838-
chmod($this->full_dst_path, $this->file_permissions);
838+
if ($this->dynamic_output !== TRUE)
839+
{
840+
chmod($this->full_dst_path, $this->file_permissions);
841+
}
839842

840843
return TRUE;
841844
}

system/libraries/Xmlrpc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,7 @@ public function parseResponse($fp)
11811181
$data = implode("\r\n", $lines);
11821182

11831183
// Parse XML data
1184-
if ( ! xml_parse($parser, $data, count($data)))
1184+
if ( ! xml_parse($parser, $data, TRUE))
11851185
{
11861186
$errstr = sprintf('XML error: %s at line %d',
11871187
xml_error_string(xml_get_error_code($parser)),

0 commit comments

Comments
 (0)