diff options
| author | Antony Dovgal <tony2001@php.net> | 2006-07-12 13:08:38 +0000 |
|---|---|---|
| committer | Antony Dovgal <tony2001@php.net> | 2006-07-12 13:08:38 +0000 |
| commit | f9070e626aea3cf1f6f48abba15e29b451ac6681 (patch) | |
| tree | 377aed37e44e87b7a10089ce506753879e46ef10 /ext/dbase | |
| parent | 69d6fe45c86726612ac8e5d532695366bd0303a5 (diff) | |
| download | php-git-f9070e626aea3cf1f6f48abba15e29b451ac6681.tar.gz | |
bailout on error and don't try to create fields of unknown type
add test
Diffstat (limited to 'ext/dbase')
| -rw-r--r-- | ext/dbase/dbase.c | 2 | ||||
| -rw-r--r-- | ext/dbase/tests/001.phpt | 61 |
2 files changed, 63 insertions, 0 deletions
diff --git a/ext/dbase/dbase.c b/ext/dbase/dbase.c index a4c6ce2eac..d9fdf36bb0 100644 --- a/ext/dbase/dbase.c +++ b/ext/dbase/dbase.c @@ -713,6 +713,8 @@ PHP_FUNCTION(dbase_create) 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; diff --git a/ext/dbase/tests/001.phpt b/ext/dbase/tests/001.phpt new file mode 100644 index 0000000000..51a4488708 --- /dev/null +++ b/ext/dbase/tests/001.phpt @@ -0,0 +1,61 @@ +--TEST-- +dbase_create() tests +--SKIPIF-- +<?php if (!extension_loaded("dbase")) print "skip"; ?> +--FILE-- +<?php + +$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) + +Warning: dbase_create(): unknown field type 'E' in %s on line %d +bool(false) + +Warning: dbase_create(): unknown field type '-' in %s on line %d +bool(false) +int(%d) + +Warning: dbase_create(): expected field name as first element of list in field 0 in %s on line %d +bool(false) +int(%d) + +Warning: dbase_create(): Expected array as second parameter in %s on line %d +bool(false) + +Warning: dbase_create(): Expected array as second parameter in %s on line %d +bool(false) +Done |
