From ef9b51bcb04e768075898621a28cf1b5a7a1551c Mon Sep 17 00:00:00 2001 From: Rasmus Lerdorf Date: Mon, 7 Oct 2002 16:46:38 +0000 Subject: [PATCH] readdir() was returning NULL instead of FALSE when used on an invalid directory handle. If someone forgot to check (as someone here did) that the opendir() succeeded, and then followed the documented usage by checking readdir()!==FALSE things would go awry. The ZEND_FETCH_RESOURCE macro explicitly does a RETURN_NULL on failure which is not what we want in this case, so work around it. No need to change it for the OO case since the object is not created if the opendir fails. --- ext/standard/dir.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ext/standard/dir.c b/ext/standard/dir.c index 7cc982cacc9..4512d69ddc9 100644 --- a/ext/standard/dir.c +++ b/ext/standard/dir.c @@ -85,7 +85,9 @@ static zend_class_entry *dir_class_entry_ptr; } else if ((ZEND_NUM_ARGS() != 1) || zend_get_parameters_ex(1, &id) == FAILURE) { \ WRONG_PARAM_COUNT; \ } else { \ - ZEND_FETCH_RESOURCE(dirp, php_stream *, id,-1, "Directory", php_file_le_stream()); \ + dirp = (php_stream *) zend_fetch_resource(id TSRMLS_CC, -1, "Directory", NULL, 1, php_file_le_stream()); \ + if(!dirp) \ + RETURN_FALSE; \ } static zend_function_entry php_dir_class_functions[] = {