diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2016-11-14 22:40:40 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2016-11-14 22:40:40 -0500 |
commit | a7e08e893eb796637ca2c53cd32a529f453ace12 (patch) | |
tree | 73f6bdc3e00baab465b5b90e963af94391f6d984 /eval.c | |
parent | 196cf9f617ca17acec75eafbcd9e5e7989752dcb (diff) | |
download | bfs-a7e08e893eb796637ca2c53cd32a529f453ace12.tar.xz |
Check for readdir() errors everywhere.
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -498,14 +498,23 @@ bool eval_empty(const struct expr *expr, struct eval_state *state) { ret = true; - struct dirent *de; - while ((de = readdir(dir)) != NULL) { + while (true) { + struct dirent *de; + if (xreaddir(dir, &de) != 0) { + eval_error(state); + goto done_dir; + } + if (!de) { + break; + } + if (strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0) { ret = false; break; } } + done_dir: closedir(dir); } else { const struct stat *statbuf = fill_statbuf(state); @@ -1038,8 +1047,11 @@ static int infer_fdlimit(const struct cmdline *cmdline) { // Account for 'dir' itself nopen = -1; - struct dirent *de; - while ((de = readdir(dir)) != NULL) { + while (true) { + struct dirent *de; + if (xreaddir(dir, &de) != 0 || !de) { + break; + } if (strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0) { ++nopen; } |