cvs: php-src /ext/dbase dbase.c /ext/dbase/tests 001.phpt
| From: | Antony Dovgal | Date: | Wed, 12 Jul 2006 13:17:25 +0000 |
| Subject: | cvs: php-src /ext/dbase dbase.c /ext/dbase/tests 001.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-39167@lists.php.net to get a copy of this message | ||
tony2001 Wed Jul 12 13:17:25 2006 UTC
Modified files:
/php-src/ext/dbase dbase.c
/php-src/ext/dbase/tests 001.phpt
Log:
restore missing check and prevent segfaulting
MFB and add test
http://cvs.php.net/viewvc.cgi/php-src/ext/dbase/dbase.c?r1=1.81&r2=1.82&diff_format=u
Index: php-src/ext/dbase/dbase.c
diff -u php-src/ext/dbase/dbase.c:1.81 php-src/ext/dbase/dbase.c:1.82
--- php-src/ext/dbase/dbase.c:1.81 Thu Jun 15 16:25:12 2006
+++ php-src/ext/dbase/dbase.c Wed Jul 12 13:17:25 2006
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: dbase.c,v 1.81 2006/06/15 16:25:12 bjori Exp $ */
+/* $Id: dbase.c,v 1.82 2006/07/12 13:17:25 tony2001 Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -573,6 +573,11 @@
}
convert_to_string_ex(filename);
+ if (Z_TYPE_PP(fields) != IS_ARRAY) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected array as second parameter");
+ RETURN_FALSE;
+ }
+
if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) {
RETURN_FALSE;
}
@@ -685,6 +690,8 @@
break;
default:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unknown field type '%c'",
cur_f->db_type);
+ free_dbf_head(dbh);
+ RETURN_FALSE;
}
cur_f->db_foffset = rlen;
rlen += cur_f->db_flen;
http://cvs.php.net/viewvc.cgi/php-src/ext/dbase/tests/001.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/dbase/tests/001.phpt
diff -u /dev/null php-src/ext/dbase/tests/001.phpt:1.2
--- /dev/null Wed Jul 12 13:17:25 2006
+++ php-src/ext/dbase/tests/001.phpt Wed Jul 12 13:17:25 2006
@@ -0,0 +1,65 @@
+--TEST--
+dbase_create() tests
+--SKIPIF--
+<?php if (!extension_loaded("dbase")) print "skip"; ?>
+--FILE--
+<?php
+
+function my_error_handler($errno, $errstr, $errfile, $errline) {
+ var_dump($errstr);
+}
+
+set_error_handler('my_error_handler');
+
+$fields_arr = Array(
+ Array(
+ array('date','D'),
+ ),
+ Array(
+ array('error', 'E'),
+ ),
+ Array(
+ array('error', -1),
+ ),
+ Array(
+ array(-1, 'N', 3, 0),
+ ),
+ Array(
+ array(),
+ ),
+ Array(
+ ),
+);
+
+$file = dirname(__FILE__).'/001.dbf';
+
+foreach ($fields_arr as $fields) {
+ var_dump(dbase_create($file, $fields));
+ @unlink($file);
+}
+
+var_dump(dbase_create($file, -1));
+@unlink($file);
+
+var_dump(dbase_create("", ""));
+
+echo "Done\n";
+?>
+--EXPECTF--
+int(%d)
+string(38) "dbase_create(): unknown field type 'E'"
+bool(false)
+string(38) "dbase_create(): unknown field type '-'"
+bool(false)
+int(%d)
+string(71) "dbase_create(): expected field name as first element of list in field 0"
+bool(false)
+int(%d)
+string(67) "Argument 2 passed to dbase_create() must be an array, integer given"
+string(50) "dbase_create(): Expected array as second parameter"
+bool(false)
+string(%d) "unlink(%s001.dbf): No such file or directory"
+string(66) "Argument 2 passed to dbase_create() must be an array, string given"
+string(50) "dbase_create(): Expected array as second parameter"
+bool(false)
+Done