From dd2eafd32cd4da1c5aa816b367073c3f56e67f5c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 23 Jan 2017 13:43:49 +0000 Subject: [PATCH] Do not ignore errors from readdir. Closes:#827408 Contribution from Peter Benie. --- debian/changelog | 3 ++- overlord.c | 3 ++- parser.c | 8 +++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/debian/changelog b/debian/changelog index c87457f..a0d0b4d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,9 @@ userv (1.1.2~~iwj1) unstable; urgency=low - Parser fixes: + Bugfixes: * Support `stdin', `stdout' and `stderr' in fd ranges, as promised by the spec. Closes:#813005. + * Do not ignore errors from readdir. Closes:#827408 [Peter Benie]. Upstream Makefiles: * Honour XCFLAGS. diff --git a/overlord.c b/overlord.c index 8f0dcb8..2ae8250 100644 --- a/overlord.c +++ b/overlord.c @@ -68,7 +68,7 @@ static void checkstalepipes(void) { if (time(&now) == -1) { syslog(LOG_ERR,"get current time: %m"); return; } dir= opendir("."); if (!dir) { syslog(LOG_ERR,"open directory " VARDIR ": %m"); return; } - while ((de= readdir(dir))) { + while ((errno=0, de= readdir(dir))) { if (fnmatch(PIPEPATTERN,de->d_name,FNM_PATHNAME|FNM_PERIOD)) continue; r= lstat(de->d_name,&stab); if (r && errno==ENOENT) continue; if (r) { syslog(LOG_ERR,"could not stat `" VARDIR "/%s': %m",de->d_name); continue; } @@ -77,6 +77,7 @@ static void checkstalepipes(void) { if (unlink(de->d_name) && errno!=ENOENT) syslog(LOG_ERR,"could not remove stale pipe `%s': %m",de->d_name); } + if (errno) syslog(LOG_ERR,"read directory " VARDIR ": %m"); if (closedir(dir)) syslog(LOG_ERR,"close directory " VARDIR ": %m"); } diff --git a/parser.c b/parser.c index a5b5fb5..257eb3e 100644 --- a/parser.c +++ b/parser.c @@ -997,7 +997,7 @@ int df_includedirectory(int dtoken) { return parseerrprint("unable to open directory `%s': %s",cpget,strerror(errno)); cp= xstrsave(cpget); cpl= strlen(cp); - while ((de= readdir(d))) { + while ((errno=0, de= readdir(d))) { tel= strlen(de->d_name); if (!tel) continue; p= de->d_name; @@ -1016,6 +1016,12 @@ int df_includedirectory(int dtoken) { goto x_err; } } + if (errno) { + parseerrprint("error reading directory `%s': %s",cp,strerror(errno)); + closedir(d); + free(cp); + return tokv_error; + } if (closedir(d)) { parseerrprint("error closing directory `%s': %s",cp,strerror(errno)); free(cp); -- 2.30.2