Browse Source

closeder/readdir/rewinddir must work only with directories

PHP-5.2.1RC1
Dmitry Stogov 18 years ago
parent
commit
6cd3a97ce2
  1. 15
      ext/standard/dir.c
  2. 2
      main/php_streams.h
  3. 2
      main/streams/streams.c

15
ext/standard/dir.c

@ -260,6 +260,11 @@ PHP_FUNCTION(closedir)
FETCH_DIRP(); 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; rsrc_id = dirp->rsrc_id;
zend_list_delete(dirp->rsrc_id); zend_list_delete(dirp->rsrc_id);
@ -360,6 +365,11 @@ PHP_FUNCTION(rewinddir)
FETCH_DIRP(); 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); php_stream_rewinddir(dirp);
} }
/* }}} */ /* }}} */
@ -374,6 +384,11 @@ PHP_NAMED_FUNCTION(php_if_readdir)
FETCH_DIRP(); 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)) { if (php_stream_readdir(dirp, &entry)) {
RETURN_STRINGL(entry.d_name, strlen(entry.d_name), 1); RETURN_STRINGL(entry.d_name, strlen(entry.d_name), 1);
} }

2
main/php_streams.h

@ -181,6 +181,8 @@ struct _php_stream_wrapper {
#define PHP_STREAM_FLAG_NO_CLOSE 32 #define PHP_STREAM_FLAG_NO_CLOSE 32
#define PHP_STREAM_FLAG_IS_DIR 64
struct _php_stream { struct _php_stream {
php_stream_ops *ops; php_stream_ops *ops;
void *abstract; /* convenience pointer for abstraction */ void *abstract; /* convenience pointer for abstraction */

2
main/streams/streams.c

@ -1706,7 +1706,7 @@ PHPAPI php_stream *_php_stream_opendir(char *path, int options,
if (stream) { if (stream) {
stream->wrapper = wrapper; 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) { } else if (wrapper) {
php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS TSRMLS_CC, "not implemented"); php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS TSRMLS_CC, "not implemented");

Loading…
Cancel
Save