]> granicus.if.org Git - php/commitdiff
closeder/readdir/rewinddir must work only with directories
authorDmitry Stogov <dmitry@php.net>
Wed, 11 Jun 2008 09:01:44 +0000 (09:01 +0000)
committerDmitry Stogov <dmitry@php.net>
Wed, 11 Jun 2008 09:01:44 +0000 (09:01 +0000)
ext/standard/dir.c
ext/standard/tests/dir/readdir_variation7.phpt
ext/standard/tests/dir/rewinddir_basic.phpt
main/php_streams.h
main/streams/streams.c

index 42140297ee3d3e82723b7d688fa894666b8965d7..0b1caa08a62121de5a01c68ca875d6aafedddc67 100644 (file)
@@ -282,6 +282,11 @@ PHP_FUNCTION(closedir)
 
        FETCH_DIRP();
 
+       if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a valid Directory resource", dirp->rsrc_id);
+               RETURN_FALSE;
+       }
+
        rsrc_id = dirp->rsrc_id;
        zend_list_delete(dirp->rsrc_id);
 
@@ -384,6 +389,11 @@ PHP_FUNCTION(rewinddir)
        
        FETCH_DIRP();
 
+       if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a valid Directory resource", dirp->rsrc_id);
+               RETURN_FALSE;
+       }
+
        php_stream_rewinddir(dirp);
 }
 /* }}} */
@@ -398,6 +408,11 @@ PHP_NAMED_FUNCTION(php_if_readdir)
 
        FETCH_DIRP();
 
+       if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a valid Directory resource", dirp->rsrc_id);
+               RETURN_FALSE;
+       }
+
        if (php_stream_readdir(dirp, &entry)) {
                RETURN_RT_STRINGL(entry.d_name, strlen(entry.d_name), ZSTR_DUPLICATE);
        }
index e62e5a3b6ad283365adec0f6b7181962ac5e3e50..86bd43061e7a8887ec1383007fd8dcc3248d8b79 100644 (file)
@@ -33,3 +33,4 @@ resource(%d) of type (stream)
 
 Warning: readdir(): %d is not a valid Directory resource in %s on line %d
 bool(false)
+===DONE===
index f2b4235a1341cf7a05915e88ef82a51594b48704..22174444fab232e0dcaeb13873565062e9844fff 100644 (file)
@@ -69,16 +69,26 @@ resource(%d) of type (stream)
 resource(%d) of type (stream)
 
 -- Read and rewind first directory (argument supplied) --
-unicode(1) "."
-unicode(2) ".."
-unicode(9) "file1.tmp"
+array(3) {
+  [0]=>
+  unicode(1) "."
+  [1]=>
+  unicode(2) ".."
+  [2]=>
+  unicode(9) "file1.tmp"
+}
 NULL
 unicode(1) "."
 
 -- Read and rewind second directory (no argument supplied) --
-unicode(1) "."
-unicode(2) ".."
-unicode(9) "file2.tmp"
+array(3) {
+  [0]=>
+  unicode(1) "."
+  [1]=>
+  unicode(2) ".."
+  [2]=>
+  unicode(9) "file2.tmp"
+}
 NULL
 unicode(1) "."
 ===DONE===
index 44606f26b9a44cd2de0c5967962fcf2fbe0f910d..4368aa8a292b9d4fa3be8249123df6abebe13e09 100755 (executable)
@@ -189,6 +189,8 @@ struct _php_stream_wrapper  {
 
 #define PHP_STREAM_FLAG_NO_CLOSE                                       32
        
+#define PHP_STREAM_FLAG_IS_DIR                                         64
+
 struct _php_stream  {
        php_stream_ops *ops;
        void *abstract;                 /* convenience pointer for abstraction */
index e917d38952c8ca173ca80e6da1b1e411abadef6d..cbc3a25301a8360d1aa865ae7d092b0b655a001d 100755 (executable)
@@ -2279,7 +2279,7 @@ PHPAPI php_stream *_php_stream_opendir(char *path, int options,
 
                if (stream) {
                        stream->wrapper = wrapper;
-                       stream->flags |= PHP_STREAM_FLAG_NO_BUFFER;
+                       stream->flags |= PHP_STREAM_FLAG_NO_BUFFER | PHP_STREAM_FLAG_IS_DIR;
                }
        } else if (wrapper) {
                php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS TSRMLS_CC, "not implemented");