From: Antony Dovgal Date: Sun, 25 Feb 2007 23:17:12 +0000 (+0000) Subject: MFH: do not allow db without fields X-Git-Tag: php-5.2.2RC1~271 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fb3a3b72f19c891b1e29f440c8108e6965b1b25b;p=php MFH: do not allow db without fields --- diff --git a/ext/dbase/dbase.c b/ext/dbase/dbase.c index 6c13bb6dcc..eb1963e3f2 100644 --- a/ext/dbase/dbase.c +++ b/ext/dbase/dbase.c @@ -621,6 +621,11 @@ PHP_FUNCTION(dbase_create) num_fields = zend_hash_num_elements(Z_ARRVAL_PP(fields)); + if (num_fields <= 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create database without fields"); + RETURN_FALSE; + } + /* have to use regular malloc() because this gets free()d by code in the dbase library */ dbh = (dbhead_t *)malloc(sizeof(dbhead_t)); diff --git a/ext/dbase/tests/001.phpt b/ext/dbase/tests/001.phpt index 51a4488708..7c10efb267 100644 --- a/ext/dbase/tests/001.phpt +++ b/ext/dbase/tests/001.phpt @@ -51,7 +51,9 @@ 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(): Unable to create database without fields in %s on line %d +bool(false) Warning: dbase_create(): Expected array as second parameter in %s on line %d bool(false)