Skip to content

Commit

Permalink
Merge branch 'PHP-5.4' into PHP-5.5
Browse files Browse the repository at this point in the history
* PHP-5.4:
  Copy dba_*() keys before converting to string.
  • Loading branch information
LawnGnome committed Sep 22, 2013
2 parents 3f64d35 + 30e0442 commit a92a350
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ PHP NEWS
. Fixed bug #65548 (Comparison for DateTimeImmutable doesn't work).
(Boro Sitnikovski)

- DBA extension:
. Fixed bug #65708 (dba functions cast $key param to string in-place,
bypassing copy on write). (Adam)

- GD
. Ensure that the defined interpolation method is used with the generic
scaling methods. (Pierre)
Expand Down
25 changes: 19 additions & 6 deletions ext/dba/dba.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,17 @@ static size_t php_dba_make_key(zval *key, char **key_str, char **key_free TSRMLS
*key_free = *key_str;
return len;
} else {
*key_free = NULL;
zval tmp = *key;
int len;

convert_to_string(key);
*key_str = Z_STRVAL_P(key);
zval_copy_ctor(&tmp);
convert_to_string(&tmp);

return Z_STRLEN_P(key);
*key_free = *key_str = estrndup(Z_STRVAL(tmp), Z_STRLEN(tmp));
len = Z_STRLEN(tmp);

zval_dtor(&tmp);
return len;
}
}
/* }}} */
Expand Down Expand Up @@ -297,6 +302,14 @@ static size_t php_dba_make_key(zval *key, char **key_str, char **key_free TSRMLS
RETURN_FALSE; \
}

/* the same check, but with a call to DBA_ID_DONE before returning */
#define DBA_WRITE_CHECK_WITH_ID \
if(info->mode != DBA_WRITER && info->mode != DBA_TRUNC && info->mode != DBA_CREAT) { \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "You cannot perform a modification to a database without proper access"); \
DBA_ID_DONE; \
RETURN_FALSE; \
}

/* }}} */

/* {{{ globals */
Expand Down Expand Up @@ -557,7 +570,7 @@ static void php_dba_update(INTERNAL_FUNCTION_PARAMETERS, int mode)

DBA_FETCH_RESOURCE(info, &id);

DBA_WRITE_CHECK;
DBA_WRITE_CHECK_WITH_ID;

if (info->hnd->update(info, key_str, key_len, val, val_len, mode TSRMLS_CC) == SUCCESS) {
DBA_ID_DONE;
Expand Down Expand Up @@ -1110,7 +1123,7 @@ PHP_FUNCTION(dba_delete)
{
DBA_ID_GET2;

DBA_WRITE_CHECK;
DBA_WRITE_CHECK_WITH_ID;

if(info->hnd->delete(info, key_str, key_len TSRMLS_CC) == SUCCESS)
{
Expand Down
38 changes: 38 additions & 0 deletions ext/dba/tests/bug65708.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--TEST--
Bug #65708 (dba functions cast $key param to string in-place, bypassing copy on write)
--SKIPIF--
<?php
require_once(dirname(__FILE__) .'/skipif.inc');
?>
--FILE--
<?php

error_reporting(E_ALL);

require_once(dirname(__FILE__) .'/test.inc');

$db = dba_popen($db_filename, 'c');

$key = 1;
$copy = $key;

echo gettype($key)."\n";
echo gettype($copy)."\n";

dba_exists($key, $db);

echo gettype($key)."\n";
echo gettype($copy)."\n";

dba_close($db);

?>
--CLEAN--
<?php
require(dirname(__FILE__) .'/clean.inc');
?>
--EXPECT--
integer
integer
integer
integer

0 comments on commit a92a350

Please sign in to comment.