if (mode == DOM_LOAD_FILE) {
char *file_dest;
if (CHECK_NULL_PATH(source, source_len)) {
+ zend_value_error("Path to document must not contain any null bytes");
return NULL;
}
file_dest = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN);
}
if (!source_len) {
- php_error_docref(NULL, E_WARNING, "Empty string supplied as input");
- RETURN_FALSE;
+ zend_argument_value_error(1, "must not be empty");
+ RETURN_THROWS();
}
if (ZEND_SIZE_T_INT_OVFL(source_len)) {
php_error_docref(NULL, E_WARNING, "Input string is too long");
}
if (file_len == 0) {
- php_error_docref(NULL, E_WARNING, "Invalid Filename");
- RETURN_FALSE;
+ zend_argument_value_error(1, "must not be empty");
+ RETURN_THROWS();
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
RETURN_THROWS();
}
- if (source_len == 0) {
- php_error_docref(NULL, E_WARNING, "Invalid Schema source");
- RETURN_FALSE;
+ if (!source_len) {
+ zend_argument_value_error(1, "must not be empty");
+ RETURN_THROWS();
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
switch (type) {
case DOM_LOAD_FILE:
if (CHECK_NULL_PATH(source, source_len)) {
- php_error_docref(NULL, E_WARNING, "Invalid Schema file source");
- RETURN_FALSE;
+ zend_argument_value_error(1, "must not contain any null bytes");
+ RETURN_THROWS();
}
valid_file = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN);
if (!valid_file) {
RETURN_THROWS();
}
- if (source_len == 0) {
- php_error_docref(NULL, E_WARNING, "Invalid Schema source");
- RETURN_FALSE;
+ if (!source_len) {
+ zend_argument_value_error(1, "must not be empty");
+ RETURN_THROWS();
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
switch (type) {
case DOM_LOAD_FILE:
if (CHECK_NULL_PATH(source, source_len)) {
- php_error_docref(NULL, E_WARNING, "Invalid RelaxNG file source");
- RETURN_FALSE;
+ zend_argument_value_error(1, "must not contain any null bytes");
+ RETURN_THROWS();
}
valid_file = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN);
if (!valid_file) {
}
if (!source_len) {
- php_error_docref(NULL, E_WARNING, "Empty string supplied as input");
- RETURN_FALSE;
+ zend_argument_value_error(1, "must not be empty");
+ RETURN_THROWS();
}
if (ZEND_LONG_EXCEEDS_INT(options)) {
if (mode == DOM_LOAD_FILE) {
if (CHECK_NULL_PATH(source, source_len)) {
- php_error_docref(NULL, E_WARNING, "Invalid file source");
- RETURN_FALSE;
+ zend_argument_value_error(1, "must not contain any null bytes");
+ RETURN_THROWS();
}
ctxt = htmlCreateFileParserCtxt(source, NULL);
} else {
}
if (file_len == 0) {
- php_error_docref(NULL, E_WARNING, "Invalid Filename");
- RETURN_FALSE;
+ zend_argument_value_error(1, "must not be empty");
+ RETURN_THROWS();
}
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
--FILE--
<?php
$doc = new DOMDocument();
-$doc->loadHTML('');
+try {
+ $doc->loadHTML('');
+} catch (ValueError $e) {
+ echo $e->getMessage() . "\n";
+}
?>
---EXPECTF--
-Warning: DOMDocument::loadHTML(): Empty string supplied as input in %s on line %d
+--EXPECT--
+DOMDocument::loadHTML(): Argument #1 ($source) must not be empty
--FILE--
<?php
$doc = new DOMDocument();
-$result = $doc->loadHTMLFile("");
-assert($result === false);
+try {
+ $result = $doc->loadHTMLFile("");
+} catch (ValueError $e) {
+ echo $e->getMessage() . "\n";
+}
+
$doc = new DOMDocument();
-$result = $doc->loadHTMLFile("text.html\0something");
-assert($result === false);
+try {
+ $result = $doc->loadHTMLFile("text.html\0something");
+} catch (ValueError $e) {
+ echo $e->getMessage() . "\n";
+}
?>
---EXPECTF--
-%r(PHP ){0,1}%rWarning: DOMDocument::loadHTMLFile(): Empty string supplied as input %s
-
-%r(PHP ){0,1}%rWarning: DOMDocument::loadHTMLFile(): Invalid file source %s
+--EXPECT--
+DOMDocument::loadHTMLFile(): Argument #1 ($filename) must not be empty
+DOMDocument::loadHTMLFile(): Argument #1 ($filename) must not contain any null bytes
--- /dev/null
+--TEST--
+Test DOMDocument::loadXML() with empty file path
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+// create dom document
+$dom = new DOMDocument();
+try {
+ $dom->loadXML("");
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
+?>
+--EXPECT--
+DOMDocument::loadXML(): Argument #1 ($source) must not be empty
--- /dev/null
+--TEST--
+Test DOMDocument::load() with invalid paths
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+// create dom document
+$dom = new DOMDocument();
+try {
+ $dom->load("");
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
+
+try {
+ $dom->load("/path/with/\0/byte");
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
+
+// Path is too long
+var_dump($dom->load(str_repeat(" ", PHP_MAXPATHLEN + 1)));
+?>
+--EXPECT--
+DOMDocument::load(): Argument #1 ($filename) must not be empty
+Path to document must not contain any null bytes
+bool(false)
$title = $head->appendChild($title);
$text = $doc->createTextNode('This is the title');
$text = $title->appendChild($text);
-$bytes = $doc->saveHTMLFile($filename);
+try {
+ $doc->saveHTMLFile($filename);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
?>
---EXPECTF--
-Warning: DOMDocument::saveHTMLFile(): Invalid Filename in %s on line %d
+--EXPECT--
+DOMDocument::saveHTMLFile(): Argument #1 ($filename) must not be empty
$doc->load(__DIR__."/book.xml");
-$result = $doc->schemaValidateSource('');
-var_dump($result);
+try {
+ $doc->schemaValidateSource('');
+} catch (ValueError $e) {
+ echo $e->getMessage() . "\n";
+}
?>
---EXPECTF--
-Warning: DOMDocument::schemaValidateSource(): Invalid Schema source in %s.php on line %d
-bool(false)
+--EXPECT--
+DOMDocument::schemaValidateSource(): Argument #1 ($source) must not be empty
$doc->load(__DIR__."/book.xml");
-$result = $doc->schemaValidate('');
-var_dump($result);
+try {
+ $doc->schemaValidate('');
+} catch (ValueError $e) {
+ echo $e->getMessage() . "\n";
+}
?>
---EXPECTF--
-Warning: DOMDocument::schemaValidate(): Invalid Schema source in %s.php on line %d
-bool(false)
+--EXPECT--
+DOMDocument::schemaValidate(): Argument #1 ($filename) must not be empty
--- /dev/null
+--TEST--
+DomDocument::schemaValidate() - invalid path to schema
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+
+$doc = new DOMDocument;
+
+$doc->load(__DIR__."/book.xml");
+
+try {
+ $doc->schemaValidate("/path/with/\0/byte");
+} catch (ValueError $e) {
+ echo $e->getMessage() . "\n";
+}
+
+var_dump($doc->schemaValidate(str_repeat(" ", PHP_MAXPATHLEN + 1)));
+
+?>
+--EXPECTF--
+DOMDocument::schemaValidate(): Argument #1 ($filename) must not contain any null bytes
+
+Warning: DOMDocument::schemaValidate(): Invalid Schema file source in %s on line %d
+bool(false)
goto clean;
}
if (CHECK_NULL_PATH(buffer, buffer_len)) {
- zend_argument_type_error(1, "must not contain null bytes");
+ zend_argument_type_error(1, "must not contain any null bytes");
goto clean;
}
?>
--EXPECTF--
-finfo_file(): Argument #1 ($finfo) must not contain null bytes
+finfo_file(): Argument #1 ($finfo) must not contain any null bytes
finfo_file(): Argument #1 ($finfo) cannot be empty
finfo_file(): Argument #1 ($finfo) cannot be empty
string(9) "directory"
string(28) "text/x-php; charset=us-ascii"
string(22) "PHP script, ASCII text"
string(25) "text/plain; charset=utf-8"
-finfo_file(): Argument #1 ($finfo) must not contain null bytes
+finfo_file(): Argument #1 ($finfo) must not contain any null bytes
Warning: mime_content_type(foo/inexistent): Failed to open stream: No such file or directory in %s on line %d
mime_content_type(): Argument #1 ($filename) cannot be empty
-mime_content_type(): Argument #1 ($filename) must not contain null bytes
+mime_content_type(): Argument #1 ($filename) must not contain any null bytes
db_obj = Z_SQLITE3_DB_P(object);
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "ssl|sl", &table, &table_len, &column, &column_len, &rowid, &dbname, &dbname_len, &flags) == FAILURE) {
- RETURN_THROWS();
- }
-
- if (ZEND_NUM_ARGS() >= 4 && CHECK_NULL_PATH(dbname, dbname_len)) {
- zend_argument_type_error(4, "must not contain null bytes");
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ssl|pl", &table, &table_len, &column, &column_len, &rowid, &dbname, &dbname_len, &flags) == FAILURE) {
RETURN_THROWS();
}
sqlite3_backup *dbBackup;
int rc; // Return code
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|ss", &destination_zval, php_sqlite3_sc_entry, &source_dbname, &source_dbname_length, &destination_dbname, &destination_dbname_length) == FAILURE) {
- RETURN_THROWS();
- }
-
- if (ZEND_NUM_ARGS() >= 2 && CHECK_NULL_PATH(source_dbname, source_dbname_length)) {
- zend_argument_type_error(2, "must not contain null bytes");
- RETURN_THROWS();
- }
-
- if (ZEND_NUM_ARGS() >= 3 && CHECK_NULL_PATH(destination_dbname, destination_dbname_length)) {
- zend_argument_type_error(3, "must not contain null bytes");
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|pp", &destination_zval, php_sqlite3_sc_entry, &source_dbname, &source_dbname_length, &destination_dbname, &destination_dbname_length) == FAILURE) {
RETURN_THROWS();
}