From: Alan Jenkins Date: Tue, 12 Sep 2017 15:26:50 +0000 (+0100) Subject: src/rrd_list.c: fix errno X-Git-Tag: v1.7.1~110^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19bb81cda3bdc3b3d64484956fe3a56d6d6287ca;p=thirdparty%2Frrdtool-1.x.git src/rrd_list.c: fix errno rrd_daemon expected zero errno iff there was not an error (and we forgot to provide it). list = rrd_list_r(recursive, fullpath); if (list == NULL) { /* Empty directory listing */ if (errno == 0) { goto out_send_response; } --- diff --git a/src/rrd_list.c b/src/rrd_list.c index 7a244cfd..5d7f41ea 100644 --- a/src/rrd_list.c +++ b/src/rrd_list.c @@ -123,6 +123,7 @@ static char *rrd_list_rec(int recursive, char *root, char *dirname) } closedir(dir); + errno = 0; return out; } @@ -195,12 +196,23 @@ char *rrd_list_r(int recursive, char *dirname) if (ptr != NULL && strlen(ptr) == 4) { - if (!stat(dirname, &st) && S_ISREG(st.st_mode)) { - ptr = strrchr(dirname, '/'); + if (stat(dirname, &st)) { + return NULL; + } - if (ptr) { - SANE_ASPRINTF(out, "%s\n", ptr + 1); - } + if (!S_ISREG(st.st_mode)) { + /* Same errno as if you try to open() a named socket. + * This is less misleading than e.g. EISDIR */ + errno = ENXIO; + return NULL; + } + + ptr = strrchr(dirname, '/'); + + if (ptr) { + SANE_ASPRINTF(out, "%s\n", ptr + 1); + } else { + errno = EINVAL; } return out; } @@ -211,6 +223,7 @@ char *rrd_list_r(int recursive, char *dirname) } if (!S_ISDIR(st.st_mode)) { + errno = ENOTDIR; return NULL; } return rrd_list_rec(recursive, dirname, dirname);