Skip to content

Commit bd8112a

Browse files
committed
Fix #71514: Bad dba_replace condition because of wrong API usage
We're backporting commit 9e309a2 to PHP-5.6, because it is a bugfix.
1 parent a1ff39f commit bd8112a

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PHP NEWS
66
. Fixed bug #72907 (null pointer deref, segfault in gc_remove_zval_from_buffer
77
(zend_gc.c:260)). (Laruence)
88

9+
- Dba:
10+
. Fixed bug #71514 (Bad dba_replace condition because of wrong API usage).
11+
(cmb)
12+
913
- Streams:
1014
. Fixed bug #72853 (stream_set_blocking doesn't work). (Laruence)
1115

ext/dba/libinifile/inifile.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ static int inifile_copy_to(inifile *dba, size_t pos_start, size_t pos_end, inifi
402402
return FAILURE;
403403
}
404404
php_stream_seek(dba->fp, pos_start, SEEK_SET);
405-
if (!php_stream_copy_to_stream_ex(dba->fp, fp, pos_end - pos_start, NULL)) {
405+
if (SUCCESS != php_stream_copy_to_stream_ex(dba->fp, fp, pos_end - pos_start, NULL)) {
406406
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy group [%zu - %zu] to temporary stream", pos_start, pos_end);
407407
return FAILURE;
408408
}
@@ -427,7 +427,7 @@ static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRML
427427
pos_curr = php_stream_tell(from->fp);
428428
if (pos_start != pos_next) {
429429
php_stream_seek(from->fp, pos_start, SEEK_SET);
430-
if (!php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start, NULL)) {
430+
if (SUCCESS != php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start, NULL)) {
431431
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy [%zu - %zu] from temporary stream", pos_next, pos_start);
432432
ret = FAILURE;
433433
}
@@ -446,7 +446,7 @@ static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRML
446446
}
447447
if (pos_start != pos_next) {
448448
php_stream_seek(from->fp, pos_start, SEEK_SET);
449-
if (!php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start, NULL)) {
449+
if (SUCCESS != php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start, NULL)) {
450450
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy [%zu - %zu] from temporary stream", pos_next, pos_start);
451451
ret = FAILURE;
452452
}
@@ -497,7 +497,7 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons
497497
php_stream_seek(dba->fp, 0, SEEK_END);
498498
if (pos_grp_next != (size_t)php_stream_tell(dba->fp)) {
499499
php_stream_seek(dba->fp, pos_grp_next, SEEK_SET);
500-
if (!php_stream_copy_to_stream_ex(dba->fp, fp_tmp, PHP_STREAM_COPY_ALL, NULL)) {
500+
if (SUCCESS != php_stream_copy_to_stream_ex(dba->fp, fp_tmp, PHP_STREAM_COPY_ALL, NULL)) {
501501
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy remainder to temporary stream");
502502
ret = FAILURE;
503503
}
@@ -538,7 +538,7 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons
538538
if (fp_tmp && php_stream_tell(fp_tmp)) {
539539
php_stream_seek(fp_tmp, 0, SEEK_SET);
540540
php_stream_seek(dba->fp, 0, SEEK_END);
541-
if (!php_stream_copy_to_stream_ex(fp_tmp, dba->fp, PHP_STREAM_COPY_ALL, NULL)) {
541+
if (SUCCESS != php_stream_copy_to_stream_ex(fp_tmp, dba->fp, PHP_STREAM_COPY_ALL, NULL)) {
542542
php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Could not copy from temporary stream - ini file truncated");
543543
ret = FAILURE;
544544
}

ext/dba/tests/bug71514.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Bug #71514 (Bad dba_replace condition because of wrong API usage)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('dba')) die('skip dba extension not available');
6+
if (!in_array('inifile', dba_handlers())) die('skip inifile handler not available');
7+
?>
8+
--FILE--
9+
<?php
10+
$filename = __DIR__ . DIRECTORY_SEPARATOR . 'bug71514.ini';
11+
12+
$db = dba_open($filename, 'c', 'inifile');
13+
14+
dba_insert('foo', 'value1', $db);
15+
dba_replace('foo', 'value2', $db);
16+
var_dump(dba_fetch('foo', $db));
17+
18+
dba_close($db);
19+
?>
20+
==DONE==
21+
--EXPECT--
22+
string(6) "value2"
23+
==DONE==
24+
--CLEAN--
25+
<?php
26+
$filename = __DIR__ . DIRECTORY_SEPARATOR . 'bug71514.ini';
27+
unlink($filename);
28+
?>

0 commit comments

Comments
 (0)