diff options
author | Bob Weinand <bobwei9@hotmail.com> | 2014-02-06 09:38:50 +0100 |
---|---|---|
committer | Bob Weinand <bobwei9@hotmail.com> | 2014-02-06 09:38:50 +0100 |
commit | 45d2df5f119d17804ccf6068cbe1132e118579b2 (patch) | |
tree | e3014245763e4290de480fad0b1142728314b965 /ext/dba | |
parent | b33060af82c648bb3971de9d8fe67e52781cbd7a (diff) | |
parent | e5ded6e843fc43dde4b6c65405a1d3e2ae026eb4 (diff) | |
download | php-git-broken-5.6-20140206.tar.gz |
Merge branch 'datibbaw/pow-operator' into PHP-5.6broken-5.6-20140206
Diffstat (limited to 'ext/dba')
-rw-r--r-- | ext/dba/dba_inifile.c | 5 | ||||
-rw-r--r-- | ext/dba/libinifile/inifile.c | 41 | ||||
-rw-r--r-- | ext/dba/libinifile/inifile.h | 2 | ||||
-rw-r--r-- | ext/dba/tests/bug62490.phpt | 43 | ||||
-rw-r--r-- | ext/dba/tests/dba_db4_003.phpt | 2 | ||||
-rw-r--r-- | ext/dba/tests/dba_db4_007.phpt | 2 | ||||
-rw-r--r-- | ext/dba/tests/dba_db4_010.phpt | 38 | ||||
-rw-r--r-- | ext/dba/tests/dba_handler.inc | 2 | ||||
-rw-r--r-- | ext/dba/tests/dba_inifile.phpt | 8 | ||||
-rw-r--r-- | ext/dba/tests/dba_tcadb.phpt | 6 |
10 files changed, 91 insertions, 58 deletions
diff --git a/ext/dba/dba_inifile.c b/ext/dba/dba_inifile.c index 4d8eae73ac..6067e99154 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 8c771beba4..218037ebe3 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; } @@ -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,10 +424,13 @@ 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); - 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 +449,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; } @@ -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; @@ -497,7 +500,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; } @@ -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 */ @@ -538,7 +541,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; } @@ -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 1177610185..e41dac0ca4 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 0000000000..325dd34554 --- /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=== diff --git a/ext/dba/tests/dba_db4_003.phpt b/ext/dba/tests/dba_db4_003.phpt index 7e8568c085..8708170fc1 100644 --- a/ext/dba/tests/dba_db4_003.phpt +++ b/ext/dba/tests/dba_db4_003.phpt @@ -39,8 +39,6 @@ require(dirname(__FILE__) .'/clean.inc'); database handler: db4 int(14) -Notice: dba_open(): %stest0.dbm: unexpected file type or format in %sdba_db4_003.php on line %d - Warning: dba_open(%stest0.dbm,c): Driver initialization failed for handler: db4: Invalid argument in %sdba_db4_003.php on line %d Error creating %stest0.dbm Dummy contents diff --git a/ext/dba/tests/dba_db4_007.phpt b/ext/dba/tests/dba_db4_007.phpt index bd95e0bec7..027d0af032 100644 --- a/ext/dba/tests/dba_db4_007.phpt +++ b/ext/dba/tests/dba_db4_007.phpt @@ -35,7 +35,5 @@ require(dirname(__FILE__) .'/clean.inc'); database handler: db4 int(14) -Notice: dba_popen(): %stest0.dbm: unexpected file type or format in %sdba_db4_007.php on line %d - Warning: dba_popen(%stest0.dbm,c): Driver initialization failed for handler: db4: Invalid argument in %sdba_db4_007.php on line %d Error creating %stest0.dbm diff --git a/ext/dba/tests/dba_db4_010.phpt b/ext/dba/tests/dba_db4_010.phpt deleted file mode 100644 index fb31f05835..0000000000 --- a/ext/dba/tests/dba_db4_010.phpt +++ /dev/null @@ -1,38 +0,0 @@ ---TEST-- -DBA DB4 magic_quotes_runtime Test ---SKIPIF-- -<?php -$handler = "db4"; -require_once(dirname(__FILE__) .'/skipif.inc'); -die("info $HND handler used"); -?> ---FILE-- -<?php -$handler = "db4"; -require_once(dirname(__FILE__) .'/test.inc'); -echo "database handler: $handler\n"; -if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { - ini_set('magic_quotes_runtime', 0); - dba_insert("key1", '"', $db_file); - var_dump(dba_fetch("key1", $db_file)); - ini_set('magic_quotes_runtime', 1); - var_dump(dba_fetch("key1", $db_file)); - dba_replace("key1", '\"', $db_file); - var_dump(dba_fetch("key1", $db_file)); - ini_set('magic_quotes_runtime', 0); - var_dump(dba_fetch("key1", $db_file)); - dba_close($db_file); -} else { - echo "Error creating database\n"; -} -?> ---CLEAN-- -<?php -require(dirname(__FILE__) .'/clean.inc'); -?> ---EXPECTF-- -database handler: db4 -string(1) """ -string(2) "\"" -string(2) "\"" -string(1) """ diff --git a/ext/dba/tests/dba_handler.inc b/ext/dba/tests/dba_handler.inc index a950e903af..ed2a52400a 100644 --- a/ext/dba/tests/dba_handler.inc +++ b/ext/dba/tests/dba_handler.inc @@ -82,7 +82,7 @@ do { dba_close($dba_reader); } if (($db_file = dba_popen($db_filename, 'r'.($lock_flag==''?'':'-'), $handler))!==FALSE) { - if ($handler == 'dbm') { + if ($handler == 'dbm' || $handler == "tcadb") { dba_close($db_file); } } diff --git a/ext/dba/tests/dba_inifile.phpt b/ext/dba/tests/dba_inifile.phpt index 5975d25f4d..ae06aee09f 100644 --- a/ext/dba/tests/dba_inifile.phpt +++ b/ext/dba/tests/dba_inifile.phpt @@ -12,6 +12,10 @@ DBA INIFILE handler test require_once dirname(__FILE__) .'/dba_handler.inc'; ?> ===DONE=== +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> --EXPECT-- database handler: inifile 3NYNYY @@ -19,7 +23,7 @@ Content String 2 Content 2 replaced Read during write: not allowed "key number 6" written -Failed to write "key number 6" 2nd time +"key number 6" written 2nd time Content 2 replaced 2nd time The 6th value array(3) { @@ -36,7 +40,7 @@ Content String 2 Content 2 replaced Read during write: not allowed "key number 6" written -Failed to write "key number 6" 2nd time +"key number 6" written 2nd time Content 2 replaced 2nd time The 6th value array(3) { diff --git a/ext/dba/tests/dba_tcadb.phpt b/ext/dba/tests/dba_tcadb.phpt index 28b6dd8f0b..f75aa813d4 100644 --- a/ext/dba/tests/dba_tcadb.phpt +++ b/ext/dba/tests/dba_tcadb.phpt @@ -16,6 +16,12 @@ DBA TCADB handler test require_once dirname(__FILE__) .'/dba_handler.inc'; ?> ===DONE=== +--CLEAN-- +<?php +$db_filename = $db_file = dirname(__FILE__) .'/test0.tch'; +@unlink($db_filename); +@unlink($db_filename.'.lck'); +?> --EXPECT-- database handler: tcadb 3NYNYY |