From 561746080b0b7154bfb3bdee20d426cf2ef7db17 Mon Sep 17 00:00:00 2001 From: "Kaleb S. KEITHLEY" Date: Thu, 7 Jul 2016 08:51:08 -0400 Subject: 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 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 Reviewed-on: http://review.gluster.org/14838 Smoke: Gluster Build System Reviewed-by: Niels de Vos CentOS-regression: Gluster Build System NetBSD-regression: NetBSD Build System Reviewed-by: Kotresh HR Reviewed-by: Jeff Darcy --- xlators/mgmt/glusterd/src/glusterd-hooks.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'xlators/mgmt/glusterd/src/glusterd-hooks.c') diff --git a/xlators/mgmt/glusterd/src/glusterd-hooks.c b/xlators/mgmt/glusterd/src/glusterd-hooks.c index 45a5912a1eb..cb3d38d2358 100644 --- a/xlators/mgmt/glusterd/src/glusterd-hooks.c +++ b/xlators/mgmt/glusterd/src/glusterd-hooks.c @@ -323,15 +323,16 @@ glusterd_hooks_run_hooks (char *hooks_path, glusterd_op_t op, dict_t *op_ctx, { xlator_t *this = NULL; glusterd_conf_t *priv = NULL; - runner_t runner = {0, }; - struct dirent *entry = NULL; + runner_t runner = {0,}; DIR *hookdir = NULL; + struct dirent *entry = NULL; + struct dirent scratch[2] = {{0,},}; char *volname = NULL; - char **lines = NULL; - int N = 8; /*arbitrary*/ - int lineno = 0; - int line_count = 0; - int ret = -1; + char **lines = NULL; + int N = 8; /*arbitrary*/ + int lineno = 0; + int line_count = 0; + int ret = -1; this = THIS; priv = this->private; @@ -362,7 +363,7 @@ glusterd_hooks_run_hooks (char *hooks_path, glusterd_op_t op, dict_t *op_ctx, ret = -1; line_count = 0; - GF_FOR_EACH_ENTRY_IN_DIR (entry, hookdir); + GF_FOR_EACH_ENTRY_IN_DIR (entry, hookdir, scratch); while (entry) { if (line_count == N-1) { N *= 2; @@ -376,7 +377,7 @@ glusterd_hooks_run_hooks (char *hooks_path, glusterd_op_t op, dict_t *op_ctx, line_count++; } - GF_FOR_EACH_ENTRY_IN_DIR (entry, hookdir); + GF_FOR_EACH_ENTRY_IN_DIR (entry, hookdir, scratch); } lines[line_count] = NULL; -- cgit