com php-src: fix bug #62490: ext/dba/dba_inifile.c ext/db a/libinifile/inifile.c ext/dba/libinifile/inifile.h ext /dba/tests/bug62490.phpt
| From: | Michael Wallner | Date: | Thu, 05 Dec 2013 10:04:25 +0000 |
| Subject: | com php-src: fix bug #62490: ext/dba/dba_inifile.c ext/db a/libinifile/inifile.c ext/dba/libinifile/inifile.h ext /dba/tests/bug62490.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-74248@lists.php.net to get a copy of this message | ||
Commit: 5a420c868083d741d969812b1b6ac2dc380cd1e3
Author: Michael Wallner <mike@php.net> Thu, 5 Dec 2013 11:04:25 +0100
Parents: f0c85fab45b22dae6cbb2392d0192d7fd924d274
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=5a420c868083d741d969812b1b6ac2dc380cd1e3
Log:
fix bug #62490
inifiles delete handler did not return false if the key was not found
Bugs:
https://bugs.php.net/62490
Changed paths:
M ext/dba/dba_inifile.c
M ext/dba/libinifile/inifile.c
M ext/dba/libinifile/inifile.h
A ext/dba/tests/bug62490.phpt
Diff:
diff --git a/ext/dba/dba_inifile.c b/ext/dba/dba_inifile.c
index 05ee95c..9461259 100644
--- a/ext/dba/dba_inifile.c
+++ b/ext/dba/dba_inifile.c
@@ -124,14 +124,15 @@ DBA_EXISTS_FUNC(inifile)
DBA_DELETE_FUNC(inifile)
{
int res;
+ zend_bool found = 0;
INIFILE_DATA;
INIFILE_GKEY;
- res = inifile_delete(dba, &ini_key TSRMLS_CC);
+ res = inifile_delete_ex(dba, &ini_key, &found TSRMLS_CC);
INIFILE_DONE;
- return (res == -1 ? FAILURE : SUCCESS);
+ return (res == -1 || !found ? FAILURE : SUCCESS);
}
DBA_FIRSTKEY_FUNC(inifile)
diff --git a/ext/dba/libinifile/inifile.c b/ext/dba/libinifile/inifile.c
index d6d311c..5e4b22a 100644
--- a/ext/dba/libinifile/inifile.c
+++ b/ext/dba/libinifile/inifile.c
@@ -413,7 +413,7 @@ static int inifile_copy_to(inifile *dba, size_t pos_start, size_t pos_end, inifi
/* {{{ inifile_filter
* copy from to dba while ignoring key name (group must equal)
*/
-static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRMLS_DC)
+static int inifile_filter(inifile *dba, inifile *from, const key_type *key, zend_bool *found
TSRMLS_DC)
{
size_t pos_start = 0, pos_next = 0, pos_curr;
int ret = SUCCESS;
@@ -424,6 +424,9 @@ static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRML
while(inifile_read(from, &ln TSRMLS_CC)) {
switch(inifile_key_cmp(&ln.key, key TSRMLS_CC)) {
case 0:
+ if (found) {
+ *found = (zend_bool) 1;
+ }
pos_curr = php_stream_tell(from->fp);
if (pos_start != pos_next) {
php_stream_seek(from->fp, pos_start, SEEK_SET);
@@ -458,7 +461,7 @@ static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRML
/* {{{ inifile_delete_replace_append
*/
-static int inifile_delete_replace_append(inifile *dba, const key_type *key, const val_type *value,
int append TSRMLS_DC)
+static int inifile_delete_replace_append(inifile *dba, const key_type *key, const val_type *value,
int append, zend_bool *found TSRMLS_DC)
{
size_t pos_grp_start=0, pos_grp_next;
inifile *ini_tmp = NULL;
@@ -516,7 +519,7 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons
if (key->name && strlen(key->name)) {
/* 6 */
if (!append && ini_tmp) {
- ret = inifile_filter(dba, ini_tmp, key TSRMLS_CC);
+ ret = inifile_filter(dba, ini_tmp, key, found TSRMLS_CC);
}
/* 7 */
@@ -563,7 +566,15 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key,
cons
*/
int inifile_delete(inifile *dba, const key_type *key TSRMLS_DC)
{
- return inifile_delete_replace_append(dba, key, NULL, 0 TSRMLS_CC);
+ return inifile_delete_replace_append(dba, key, NULL, 0, NULL TSRMLS_CC);
+}
+/* }}} */
+
+/* {{{ inifile_delete_ex
+ */
+int inifile_delete_ex(inifile *dba, const key_type *key, zend_bool *found TSRMLS_DC)
+{
+ return inifile_delete_replace_append(dba, key, NULL, 0, found TSRMLS_CC);
}
/* }}} */
@@ -571,7 +582,15 @@ int inifile_delete(inifile *dba, const key_type *key TSRMLS_DC)
*/
int inifile_replace(inifile *dba, const key_type *key, const val_type *value TSRMLS_DC)
{
- return inifile_delete_replace_append(dba, key, value, 0 TSRMLS_CC);
+ return inifile_delete_replace_append(dba, key, value, 0, NULL TSRMLS_CC);
+}
+/* }}} */
+
+/* {{{ inifile_replace_ex
+ */
+int inifile_replace_ex(inifile *dba, const key_type *key, const val_type *value, zend_bool *found
TSRMLS_DC)
+{
+ return inifile_delete_replace_append(dba, key, value, 0, found TSRMLS_CC);
}
/* }}} */
@@ -579,7 +598,7 @@ int inifile_replace(inifile *dba, const key_type *key, const val_type *value TSR
*/
int inifile_append(inifile *dba, const key_type *key, const val_type *value TSRMLS_DC)
{
- return inifile_delete_replace_append(dba, key, value, 1 TSRMLS_CC);
+ return inifile_delete_replace_append(dba, key, value, 1, NULL TSRMLS_CC);
}
/* }}} */
diff --git a/ext/dba/libinifile/inifile.h b/ext/dba/libinifile/inifile.h
index 5a25573..8556b8d 100644
--- a/ext/dba/libinifile/inifile.h
+++ b/ext/dba/libinifile/inifile.h
@@ -49,7 +49,9 @@ val_type inifile_fetch(inifile *dba, const key_type *key, int skip TSRMLS_DC);
int inifile_firstkey(inifile *dba TSRMLS_DC);
int inifile_nextkey(inifile *dba TSRMLS_DC);
int inifile_delete(inifile *dba, const key_type *key TSRMLS_DC);
+int inifile_delete_ex(inifile *dba, const key_type *key, zend_bool *found TSRMLS_DC);
int inifile_replace(inifile *dba, const key_type *key, const val_type *val TSRMLS_DC);
+int inifile_replace_ex(inifile *dba, const key_type *key, const val_type *val, zend_bool *found
TSRMLS_DC);
int inifile_append(inifile *dba, const key_type *key, const val_type *val TSRMLS_DC);
char *inifile_version();
diff --git a/ext/dba/tests/bug62490.phpt b/ext/dba/tests/bug62490.phpt
new file mode 100644
index 0000000...325dd34
--- /dev/null
+++ b/ext/dba/tests/bug62490.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Bug #62490 (dba_delete returns true on missing item (inifile))
+--SKIPIF--
+<?php
+$handler = "inifile";
+include "skipif.inc";
+?>
+--FILE--
+<?php
+$handler = "inifile";
+include "test.inc";
+
+$dba = dba_open($db_filename, "n", $handler)
+ or die;
+for ($i = 0; $i < 3; ++$i) {
+ echo "insert $i:";
+ var_dump(dba_insert("a", $i, $dba));
+}
+
+echo "exists:";
+var_dump(dba_exists("a", $dba));
+echo "delete:";
+var_dump(dba_delete("a", $dba));
+echo "exists:";
+var_dump(dba_exists("a", $dba));
+echo "delete:";
+var_dump(dba_delete("a", $dba));
+
+?>
+===DONE===
+--CLEAN--
+<?php
+include "clean.inc";
+?>
+--EXPECT--
+insert 0:bool(true)
+insert 1:bool(true)
+insert 2:bool(true)
+exists:bool(true)
+delete:bool(true)
+exists:bool(false)
+delete:bool(false)
+===DONE===