Skip to content

Commit b4b4372

Browse files
committed
Merge branch 'PHP-5.4' of https://git.php.net/repository/php-src into PHP-5.4
# By Adam Harvey # Via Adam Harvey * 'PHP-5.4' of https://git.php.net/repository/php-src: Copy dba_*() keys before converting to string.
2 parents 34fc79b + 30e0442 commit b4b4372

File tree

3 files changed

+61
-6
lines changed

3 files changed

+61
-6
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ PHP NEWS
1010
. Fixed bug #64157 (DateTime::createFromFormat() reports confusing error
1111
message). (Boro Sitnikovski)
1212

13+
- DBA extension:
14+
. Fixed bug #65708 (dba functions cast $key param to string in-place,
15+
bypassing copy on write). (Adam)
16+
1317
- Filter:
1418
. Add RFC 6598 IPs to reserved addresses. (Sebastian Nohn)
1519
. Fixed bug #64441 (FILTER_VALIDATE_URL rejects fully qualified domain names).

ext/dba/dba.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,17 @@ static size_t php_dba_make_key(zval *key, char **key_str, char **key_free TSRMLS
226226
*key_free = *key_str;
227227
return len;
228228
} else {
229-
*key_free = NULL;
229+
zval tmp = *key;
230+
int len;
230231

231-
convert_to_string(key);
232-
*key_str = Z_STRVAL_P(key);
232+
zval_copy_ctor(&tmp);
233+
convert_to_string(&tmp);
233234

234-
return Z_STRLEN_P(key);
235+
*key_free = *key_str = estrndup(Z_STRVAL(tmp), Z_STRLEN(tmp));
236+
len = Z_STRLEN(tmp);
237+
238+
zval_dtor(&tmp);
239+
return len;
235240
}
236241
}
237242
/* }}} */
@@ -297,6 +302,14 @@ static size_t php_dba_make_key(zval *key, char **key_str, char **key_free TSRMLS
297302
RETURN_FALSE; \
298303
}
299304

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

302315
/* {{{ globals */
@@ -557,7 +570,7 @@ static void php_dba_update(INTERNAL_FUNCTION_PARAMETERS, int mode)
557570

558571
DBA_FETCH_RESOURCE(info, &id);
559572

560-
DBA_WRITE_CHECK;
573+
DBA_WRITE_CHECK_WITH_ID;
561574

562575
if (info->hnd->update(info, key_str, key_len, val, val_len, mode TSRMLS_CC) == SUCCESS) {
563576
DBA_ID_DONE;
@@ -1110,7 +1123,7 @@ PHP_FUNCTION(dba_delete)
11101123
{
11111124
DBA_ID_GET2;
11121125

1113-
DBA_WRITE_CHECK;
1126+
DBA_WRITE_CHECK_WITH_ID;
11141127

11151128
if(info->hnd->delete(info, key_str, key_len TSRMLS_CC) == SUCCESS)
11161129
{

ext/dba/tests/bug65708.phpt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
Bug #65708 (dba functions cast $key param to string in-place, bypassing copy on write)
3+
--SKIPIF--
4+
<?php
5+
require_once(dirname(__FILE__) .'/skipif.inc');
6+
?>
7+
--FILE--
8+
<?php
9+
10+
error_reporting(E_ALL);
11+
12+
require_once(dirname(__FILE__) .'/test.inc');
13+
14+
$db = dba_popen($db_filename, 'c');
15+
16+
$key = 1;
17+
$copy = $key;
18+
19+
echo gettype($key)."\n";
20+
echo gettype($copy)."\n";
21+
22+
dba_exists($key, $db);
23+
24+
echo gettype($key)."\n";
25+
echo gettype($copy)."\n";
26+
27+
dba_close($db);
28+
29+
?>
30+
--CLEAN--
31+
<?php
32+
require(dirname(__FILE__) .'/clean.inc');
33+
?>
34+
--EXPECT--
35+
integer
36+
integer
37+
integer
38+
integer

0 commit comments

Comments
 (0)