diff options
author | Kaleb S. KEITHLEY <kkeithle@redhat.com> | 2016-07-07 08:51:08 -0400 |
---|---|---|
committer | Jeff Darcy <jdarcy@redhat.com> | 2016-07-18 04:59:42 -0700 |
commit | 561746080b0b7154bfb3bdee20d426cf2ef7db17 (patch) | |
tree | 0dd0db913055925d7843d85c8066a7c0018a290a /xlators/mgmt/glusterd/src/glusterd-volgen.c | |
parent | 73b9ede7e115fab245b0f59d18e4d6cc4d297cec (diff) |
core: use readdir(3) with glibc, and associated cleanup
Starting with glibc-2.23 (i.e. what's in Fedora 25), readdir_r(3)
is marked as deprecated. Specifically the function decl in <dirent.h>
has the deprecated attribute, and now warnings are thrown during the
compile on Fedora 25 builds.
The readdir(_r)(3) man page (on Fedora 25 at least) and World+Dog say
that glibc's readdir(3) is, and always has been, MT-SAFE as long as
only one thread is accessing the directory object returned by opendir().
World+Dog also says there is a potential buffer overflow in readdir_r().
World+Dog suggests that it is preferable to simply use readdir(). There's
an implication that eventually readdir_r(3) will be removed from glibc.
POSIX has, apparently deprecated it in the standard, or even removed it
entirely.
Over and above that, our source near the various uses of readdir(_r)(3)
has a few unsafe uses of strcpy()+strcat().
(AFAIK nobody has looked at the readdir(3) implemenation in *BSD to see
if the same is true on those platforms, and we can't be sure of MacOS
even though we know it's based on *BSD.)
Change-Id: I5481f18ba1eebe7ee177895eecc9a80a71b60568
BUG: 1356998
Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com>
Reviewed-on: http://review.gluster.org/14838
Smoke: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Niels de Vos <ndevos@redhat.com>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
Reviewed-by: Kotresh HR <khiremat@redhat.com>
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-volgen.c')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volgen.c | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index b56e9f26379..6a755486d7d 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -913,58 +913,59 @@ out: static void volgen_apply_filters (char *orig_volfile) { - DIR *filterdir = NULL; - struct dirent entry = {0,}; - struct dirent *next = NULL; - char *filterpath = NULL; - struct stat statbuf = {0,}; + DIR *filterdir = NULL; + struct dirent *entry = NULL; + struct dirent scratch[2] = {{0,},}; + struct stat statbuf = {0,}; + char filterpath[PATH_MAX] = {0,}; filterdir = sys_opendir (FILTERDIR); - if (!filterdir) { + + if (!filterdir) return; - } - while ((readdir_r(filterdir,&entry,&next) == 0) && next) { - if (!strncmp(entry.d_name,".",sizeof(entry.d_name))) { - continue; - } - if (!strncmp(entry.d_name,"..",sizeof(entry.d_name))) { + for (;;) { + + errno = 0; + + entry = sys_readdir (filterdir, scratch); + + if (!entry || errno != 0) + break; + + if (strcmp (entry->d_name, ".") == 0 || + strcmp (entry->d_name, "..") == 0) continue; - } /* * d_type isn't guaranteed to be present/valid on all systems, * so do an explicit stat instead. */ - if (gf_asprintf(&filterpath,"%s/%.*s",FILTERDIR, - sizeof(entry.d_name), entry.d_name) == (-1)) { - continue; - } + (void) snprintf (filterpath, sizeof(filterpath), "%s/%s", + FILTERDIR, entry->d_name); + /* Deliberately use stat instead of lstat to allow symlinks. */ - if (sys_stat(filterpath, &statbuf) == (-1)) { - goto free_fp; - } - if (!S_ISREG(statbuf.st_mode)) { - goto free_fp; - } + if (sys_stat (filterpath, &statbuf) == -1) + continue; + + if (!S_ISREG (statbuf.st_mode)) + continue; /* * We could check the mode in statbuf directly, or just skip * this entirely and check for EPERM after exec fails, but this * is cleaner. */ - if (sys_access(filterpath, X_OK) != 0) { - goto free_fp; - } - if (runcmd(filterpath,orig_volfile,NULL)) { + if (sys_access (filterpath, X_OK) != 0) + continue; + + if (runcmd (filterpath, orig_volfile, NULL)) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_FILTER_RUN_FAILED, - "failed to run filter %.*s", - (int)sizeof(entry.d_name), entry.d_name); + "failed to run filter %s", + entry->d_name); } -free_fp: - GF_FREE(filterpath); } - sys_closedir (filterdir); + (void) sys_closedir (filterdir); } static int @@ -979,7 +980,6 @@ volgen_write_volfile (volgen_graph_t *graph, char *filename) if (gf_asprintf (&ftmp, "%s.tmp", filename) == -1) { ftmp = NULL; - goto error; } |