Skip to content

Commit 788fb4a

Browse files
committed
Merge branch '3.0-stable' into develop
2 parents 97ecf2f + bc05b84 commit 788fb4a

20 files changed

+298
-109
lines changed

system/core/Security.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,22 @@ public function get_random_bytes($length)
593593
return FALSE;
594594
}
595595

596+
if (function_exists('random_bytes'))
597+
{
598+
try
599+
{
600+
// The cast is required to avoid TypeError
601+
return random_bytes((int) $length);
602+
}
603+
catch (Exception $e)
604+
{
605+
// If random_bytes() can't do the job, we can't either ...
606+
// There's no point in using fallbacks.
607+
log_message('error', $e->getMessage());
608+
return FALSE;
609+
}
610+
}
611+
596612
// Unfortunately, none of the following PRNGs is guaranteed to exist ...
597613
if (defined('MCRYPT_DEV_URANDOM') && ($output = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM)) !== FALSE)
598614
{

system/database/DB_driver.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,18 @@ public function db_select()
498498

499499
// --------------------------------------------------------------------
500500

501+
/**
502+
* Last error
503+
*
504+
* @return array
505+
*/
506+
public function error()
507+
{
508+
return array('code' => NULL, 'message' => NULL);
509+
}
510+
511+
// --------------------------------------------------------------------
512+
501513
/**
502514
* Set client character set
503515
*

system/database/DB_forge.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,10 +780,6 @@ protected function _process_fields($create_table = FALSE)
780780
case 'ENUM':
781781
case 'SET':
782782
$attributes['CONSTRAINT'] = $this->db->escape($attributes['CONSTRAINT']);
783-
$field['length'] = is_array($attributes['CONSTRAINT'])
784-
? "('".implode("','", $attributes['CONSTRAINT'])."')"
785-
: '('.$attributes['CONSTRAINT'].')';
786-
break;
787783
default:
788784
$field['length'] = is_array($attributes['CONSTRAINT'])
789785
? '('.implode(',', $attributes['CONSTRAINT']).')'

system/database/DB_query_builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ public function count_all_results($table = '', $reset = TRUE)
13791379
$this->from($table);
13801380
}
13811381

1382-
$result = ($this->qb_distinct === TRUE)
1382+
$result = ($this->qb_distinct === TRUE OR ! empty($this->qb_orderby))
13831383
? $this->query($this->_count_string.$this->protect_identifiers('numrows')."\nFROM (\n".$this->_compile_select()."\n) CI_count_all_results")
13841384
: $this->query($this->_compile_select($this->_count_string.$this->protect_identifiers('numrows')));
13851385

system/database/drivers/mssql/mssql_driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ protected function _db_set_charset($charset)
267267
*/
268268
protected function _version()
269269
{
270-
return 'SELECT @@VERSION AS ver';
270+
return "SELECT SERVERPROPERTY('ProductVersion') AS ver";
271271
}
272272

273273
// --------------------------------------------------------------------

system/database/drivers/oci8/oci8_driver.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,16 @@ public function version()
252252
return $this->data_cache['version'];
253253
}
254254

255-
if ( ! $this->conn_id OR ($version = oci_server_version($this->conn_id)) === FALSE)
255+
if ( ! $this->conn_id OR ($version_string = oci_server_version($this->conn_id)) === FALSE)
256256
{
257257
return FALSE;
258258
}
259+
elseif (preg_match('#Release\s(\d+(?:\.\d+)+)#', $version_string, $match))
260+
{
261+
return $this->data_cache['version'] = $match[1];
262+
}
259263

260-
return $this->data_cache['version'] = $version;
264+
return FALSE;
261265
}
262266

263267
// --------------------------------------------------------------------

system/database/drivers/pdo/subdrivers/pdo_oci_driver.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,29 @@ public function __construct($params)
129129

130130
// --------------------------------------------------------------------
131131

132+
/**
133+
* Database version number
134+
*
135+
* @return string
136+
*/
137+
public function version()
138+
{
139+
if (isset($this->data_cache['version']))
140+
{
141+
return $this->data_cache['version'];
142+
}
143+
144+
$version_string = parent::version();
145+
if (preg_match('#Release\s(?<version>\d+(?:\.\d+)+)#', $version_string, $match))
146+
{
147+
return $this->data_cache['version'] = $match[1];
148+
}
149+
150+
return FALSE;
151+
}
152+
153+
// --------------------------------------------------------------------
154+
132155
/**
133156
* Show table query
134157
*

system/helpers/captcha_helper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ function create_captcha($data = '', $img_path = '', $img_url = '', $font_path =
171171
$byte_index = $word_index = 0;
172172
while ($word_index < $word_length)
173173
{
174-
if (($rand_index = unpack('C', $bytes[$byte_index++])) > $rand_max)
174+
list(, $rand_index) = unpack('C', $bytes[$byte_index++]);
175+
if ($rand_index > $rand_max)
175176
{
176177
// Was this the last byte we have?
177178
// If so, try to fetch more.

system/helpers/form_helper.php

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -769,12 +769,11 @@ function set_checkbox($field, $value = '', $default = FALSE)
769769
{
770770
return $CI->form_validation->set_checkbox($field, $value, $default);
771771
}
772-
elseif (($input = $CI->input->post($field, FALSE)) === NULL)
773-
{
774-
return ($default === TRUE) ? ' checked="checked"' : '';
775-
}
776772

773+
// Form inputs are always strings ...
777774
$value = (string) $value;
775+
$input = $CI->input->post($field, FALSE);
776+
778777
if (is_array($input))
779778
{
780779
// Note: in_array('', array(0)) returns TRUE, do not use it
@@ -789,7 +788,13 @@ function set_checkbox($field, $value = '', $default = FALSE)
789788
return '';
790789
}
791790

792-
return ($input === $value) ? ' checked="checked"' : '';
791+
// Unchecked checkbox and radio inputs are not even submitted by browsers ...
792+
if ($CI->input->method() === 'post')
793+
{
794+
return ($input === 'value') ? ' checked="checked"' : '';
795+
}
796+
797+
return ($default === TRUE) ? ' checked="checked"' : '';
793798
}
794799
}
795800

@@ -816,12 +821,32 @@ function set_radio($field, $value = '', $default = FALSE)
816821
{
817822
return $CI->form_validation->set_radio($field, $value, $default);
818823
}
819-
elseif (($input = $CI->input->post($field, FALSE)) === NULL)
824+
825+
// Form inputs are always strings ...
826+
$value = (string) $value;
827+
$input = $CI->input->post($field, FALSE);
828+
829+
if (is_array($input))
830+
{
831+
// Note: in_array('', array(0)) returns TRUE, do not use it
832+
foreach ($input as &$v)
833+
{
834+
if ($value === $v)
835+
{
836+
return ' checked="checked"';
837+
}
838+
}
839+
840+
return '';
841+
}
842+
843+
// Unchecked checkbox and radio inputs are not even submitted by browsers ...
844+
if ($CI->input->method() === 'post')
820845
{
821-
return ($default === TRUE) ? ' checked="checked"' : '';
846+
return ($input === 'value') ? ' checked="checked"' : '';
822847
}
823848

824-
return ($input === (string) $value) ? ' checked="checked"' : '';
849+
return ($default === TRUE) ? ' checked="checked"' : '';
825850
}
826851
}
827852

system/helpers/string_helper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ function increment_string($str, $separator = '_', $first = 1)
270270
* @param string (as many parameters as needed)
271271
* @return string
272272
*/
273-
function alternator($args)
273+
function alternator()
274274
{
275275
static $i;
276276

@@ -279,6 +279,7 @@ function alternator($args)
279279
$i = 0;
280280
return '';
281281
}
282+
282283
$args = func_get_args();
283284
return $args[($i++ % count($args))];
284285
}

system/libraries/Email.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,20 @@ protected function _build_message()
14691469
*/
14701470
protected function _prep_quoted_printable($str)
14711471
{
1472+
// ASCII code numbers for "safe" characters that can always be
1473+
// used literally, without encoding, as described in RFC 2049.
1474+
// http://www.ietf.org/rfc/rfc2049.txt
1475+
static $ascii_safe_chars = array(
1476+
// ' ( ) + , - . / : = ?
1477+
39, 40, 41, 43, 44, 45, 46, 47, 58, 61, 63,
1478+
// numbers
1479+
48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
1480+
// upper-case letters
1481+
65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
1482+
// lower-case letters
1483+
97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122
1484+
);
1485+
14721486
// We are intentionally wrapping so mail servers will encode characters
14731487
// properly and MUAs will behave, so {unwrap} must go!
14741488
$str = str_replace(array('{unwrap}', '{/unwrap}'), '', $str);
@@ -1516,14 +1530,25 @@ protected function _prep_quoted_printable($str)
15161530
$ascii = ord($char);
15171531

15181532
// Convert spaces and tabs but only if it's the end of the line
1519-
if ($i === ($length - 1) && ($ascii === 32 OR $ascii === 9))
1533+
if ($ascii === 32 OR $ascii === 9)
15201534
{
1521-
$char = $escape.sprintf('%02s', dechex($ascii));
1535+
if ($i === ($length - 1))
1536+
{
1537+
$char = $escape.sprintf('%02s', dechex($ascii));
1538+
}
15221539
}
1523-
elseif ($ascii === 61) // encode = signs
1540+
// DO NOT move this below the $ascii_safe_chars line!
1541+
//
1542+
// = (equals) signs are allowed by RFC2049, but must be encoded
1543+
// as they are the encoding delimiter!
1544+
elseif ($ascii === 61)
15241545
{
15251546
$char = $escape.strtoupper(sprintf('%02s', dechex($ascii))); // =3D
15261547
}
1548+
elseif ( ! in_array($ascii, $ascii_safe_chars, TRUE))
1549+
{
1550+
$char = $escape.strtoupper(sprintf('%02s', dechex($ascii)));
1551+
}
15271552

15281553
// If we're at the character limit, add the line to the output,
15291554
// reset our temp variable, and keep on chuggin'

system/libraries/Encryption.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@ protected function _openssl_initialize($params)
337337
*/
338338
public function create_key($length)
339339
{
340+
if (function_exists('random_bytes'))
341+
{
342+
return random_bytes((int) $length);
343+
}
344+
340345
return ($this->_driver === 'mcrypt')
341346
? mcrypt_create_iv($length, MCRYPT_DEV_URANDOM)
342347
: openssl_random_pseudo_bytes($length);

system/libraries/Form_validation.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,9 @@ public function error_string($prefix = '', $suffix = '')
415415
*/
416416
public function run($group = '')
417417
{
418-
// Do we even have any data to process? Mm?
419-
$validation_array = empty($this->validation_data) ? $_POST : $this->validation_data;
420-
if (count($validation_array) === 0)
421-
{
422-
return FALSE;
423-
}
418+
$validation_array = empty($this->validation_data)
419+
? $_POST
420+
: $this->validation_data;
424421

425422
// Does the _field_data array containing the validation rules exist?
426423
// If not, we look to see if they were assigned via a config file

system/libraries/Session/Session_driver.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ abstract class CI_Session_driver implements SessionHandlerInterface {
7474
*/
7575
protected $_session_id;
7676

77+
/**
78+
* Success and failure return values
79+
*
80+
* Necessary due to a bug in all PHP 5 versions where return values
81+
* from userspace handlers are not handled properly. PHP 7 fixes the
82+
* bug, so we need to return different values depending on the version.
83+
*
84+
* @see https://wiki.php.net/rfc/session.user.return-value
85+
* @var mixed
86+
*/
87+
protected $_success, $_failure;
88+
7789
// ------------------------------------------------------------------------
7890

7991
/**
@@ -85,6 +97,17 @@ abstract class CI_Session_driver implements SessionHandlerInterface {
8597
public function __construct(&$params)
8698
{
8799
$this->_config =& $params;
100+
101+
if (is_php('7'))
102+
{
103+
$this->_success = TRUE;
104+
$this->_failure = FALSE;
105+
}
106+
else
107+
{
108+
$this->_success = 0;
109+
$this->_failure = -1;
110+
}
88111
}
89112

90113
// ------------------------------------------------------------------------

0 commit comments

Comments
 (0)