com php-src: Fix #71514: Bad dba_replace condition becaus e of wrong API usage: NEWS ext/dba/libinifile/ini file.c ext/dba/tests/bug71514.phpt
| From: | Christoph Michael Becker | Date: | Thu, 25 Aug 2016 14:20:30 +0000 |
| Subject: | com php-src: Fix #71514: Bad dba_replace condition becaus e of wrong API usage: NEWS ext/dba/libinifile/ini file.c ext/dba/tests/bug71514.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94061@lists.php.net to get a copy of this message | ||
Commit: bd8112afe076cd975fbfcf82b659f6420317de70
Author: Christoph M. Becker <cmbecker69@gmx.de> Thu, 25 Aug 2016 16:20:30 +0200
Parents: a1ff39ffe5cc3e83bd51b2511163e2e620e935d2
Branches: PHP-5.6 PHP-7..0 PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=bd8112afe076cd975fbfcf82b659f6420317de70
Log:
Fix #71514: Bad dba_replace condition because of wrong API usage
We're backporting commit 9e309a2d to PHP-5.6, because it is a bugfix.
Bugs:
https://bugs.php.net/71514
Changed paths:
M NEWS
M ext/dba/libinifile/inifile.c
A ext/dba/tests/bug71514.phpt
Diff:
diff --git a/NEWS b/NEWS
index a2b3aad..9c3cef5 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,10 @@ PHP NEWS
. Fixed bug #72907 (null pointer deref, segfault in gc_remove_zval_from_buffer
(zend_gc.c:260)). (Laruence)
+- Dba:
+ . Fixed bug #71514 (Bad dba_replace condition because of wrong API usage).
+ (cmb)
+
- Streams:
. Fixed bug #72853 (stream_set_blocking doesn't work). (Laruence)
diff --git a/ext/dba/libinifile/inifile.c b/ext/dba/libinifile/inifile.c
index 0feb5f1..9f1789b 100644
--- a/ext/dba/libinifile/inifile.c
+++ b/ext/dba/libinifile/inifile..c
@@ -402,7 +402,7 @@ static int inifile_copy_to(inifile *dba, size_t pos_start, size_t pos_end, inifi
return FAILURE;
}
php_stream_seek(dba->fp, pos_start, SEEK_SET);
- if (!php_stream_copy_to_stream_ex(dba->fp, fp, pos_end - pos_start, NULL)) {
+ if (SUCCESS != php_stream_copy_to_stream_ex(dba->fp, fp, pos_end - pos_start, NULL)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy group [%zu - %zu] to temporary
stream", pos_start, pos_end);
return FAILURE;
}
@@ -427,7 +427,7 @@ static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRML
pos_curr = php_stream_tell(from->fp);
if (pos_start != pos_next) {
php_stream_seek(from->fp, pos_start, SEEK_SET);
- if (!php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start, NULL)) {
+ if (SUCCESS != php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start,
NULL)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy [%zu - %zu] from temporary
stream", pos_next, pos_start);
ret = FAILURE;
}
@@ -446,7 +446,7 @@ static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRML
}
if (pos_start != pos_next) {
php_stream_seek(from->fp, pos_start, SEEK_SET);
- if (!php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start, NULL)) {
+ if (SUCCESS != php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start, NULL))
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy [%zu - %zu] from temporary
stream", pos_next, pos_start);
ret = FAILURE;
}
@@ -497,7 +497,7 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons
php_stream_seek(dba->fp, 0, SEEK_END);
if (pos_grp_next != (size_t)php_stream_tell(dba->fp)) {
php_stream_seek(dba->fp, pos_grp_next, SEEK_SET);
- if (!php_stream_copy_to_stream_ex(dba->fp, fp_tmp, PHP_STREAM_COPY_ALL, NULL)) {
+ if (SUCCESS != php_stream_copy_to_stream_ex(dba->fp, fp_tmp, PHP_STREAM_COPY_ALL, NULL)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy remainder to temporary
stream");
ret = FAILURE;
}
@@ -538,7 +538,7 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons
if (fp_tmp && php_stream_tell(fp_tmp)) {
php_stream_seek(fp_tmp, 0, SEEK_SET);
php_stream_seek(dba->fp, 0, SEEK_END);
- if (!php_stream_copy_to_stream_ex(fp_tmp, dba->fp, PHP_STREAM_COPY_ALL, NULL)) {
+ if (SUCCESS != php_stream_copy_to_stream_ex(fp_tmp, dba->fp, PHP_STREAM_COPY_ALL, NULL)) {
php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Could not copy from temporary
stream - ini file truncated");
ret = FAILURE;
}
diff --git a/ext/dba/tests/bug71514.phpt b/ext/dba/tests/bug71514.phpt
new file mode 100644
index 0000000..08338f3
--- /dev/null
+++ b/ext/dba/tests/bug71514.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Bug #71514 (Bad dba_replace condition because of wrong API usage)
+--SKIPIF--
+<?php
+if (!extension_loaded('dba')) die('skip dba extension not available');
+if (!in_array('inifile', dba_handlers())) die('skip inifile handler not
available');
+?>
+--FILE--
+<?php
+$filename = __DIR__ . DIRECTORY_SEPARATOR . 'bug71514.ini';
+
+$db = dba_open($filename, 'c', 'inifile');
+
+dba_insert('foo', 'value1', $db);
+dba_replace('foo', 'value2', $db);
+var_dump(dba_fetch('foo', $db));
+
+dba_close($db);
+?>
+==DONE==
+--EXPECT--
+string(6) "value2"
+==DONE==
+--CLEAN--
+<?php
+$filename = __DIR__ . DIRECTORY_SEPARATOR . 'bug71514.ini';
+unlink($filename);
+?>