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
}

0 commit comments

Comments
 (0)