summaryrefslogtreecommitdiffstats
path: root/xlators/experimental/jbr-server/src
diff options
context:
space:
mode:
authorKaleb S. KEITHLEY <kkeithle@redhat.com>2016-07-07 08:51:08 -0400
committerJeff Darcy <jdarcy@redhat.com>2016-07-18 04:59:42 -0700
commit561746080b0b7154bfb3bdee20d426cf2ef7db17 (patch)
tree0dd0db913055925d7843d85c8066a7c0018a290a /xlators/experimental/jbr-server/src
parent73b9ede7e115fab245b0f59d18e4d6cc4d297cec (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/experimental/jbr-server/src')
-rw-r--r--xlators/experimental/jbr-server/src/jbr.c53
1 files changed, 25 insertions, 28 deletions
diff --git a/xlators/experimental/jbr-server/src/jbr.c b/xlators/experimental/jbr-server/src/jbr.c
index e07c511f4a9..68badb85079 100644
--- a/xlators/experimental/jbr-server/src/jbr.c
+++ b/xlators/experimental/jbr-server/src/jbr.c
@@ -989,17 +989,17 @@ jbr_get_changelog_dir (xlator_t *this, char **cl_dir_p)
void
jbr_get_terms (call_frame_t *frame, xlator_t *this)
{
- int32_t op_errno;
- char *cl_dir;
- DIR *fp = NULL;
- struct dirent *rd_entry;
- struct dirent *rd_result;
- int32_t term_first = -1;
- int32_t term_contig = -1;
- int32_t term_last = -1;
- int term_num;
- char *probe_str;
- dict_t *my_xdata = NULL;
+ int32_t op_errno = 0;
+ char *cl_dir = NULL;
+ int32_t term_first = -1;
+ int32_t term_contig = -1;
+ int32_t term_last = -1;
+ int term_num = 0;
+ char *probe_str = NULL;
+ dict_t *my_xdata = NULL;
+ DIR *fp = NULL;
+ struct dirent *entry = NULL;
+ struct dirent scratch[2] = {{0,},};
op_errno = jbr_get_changelog_dir(this, &cl_dir);
if (op_errno) {
@@ -1007,12 +1007,6 @@ jbr_get_terms (call_frame_t *frame, xlator_t *this)
}
op_errno = ENODATA; /* Most common error after this. */
- rd_entry = alloca (offsetof(struct dirent, d_name) +
- pathconf(cl_dir, _PC_NAME_MAX) + 1);
- if (!rd_entry) {
- goto err;
- }
-
fp = sys_opendir (cl_dir);
if (!fp) {
op_errno = errno;
@@ -1021,25 +1015,28 @@ jbr_get_terms (call_frame_t *frame, xlator_t *this)
/* Find first and last terms. */
for (;;) {
- if (readdir_r(fp, rd_entry, &rd_result) != 0) {
- op_errno = errno;
- goto err;
- }
- if (!rd_result) {
+ errno = 0;
+ entry = sys_readdir (fp, scratch);
+ if (!entry || errno != 0) {
+ if (errno != 0) {
+ op_errno = errno;
+ goto err;
+ }
break;
}
- if (fnmatch("TERM.*", rd_entry->d_name, FNM_PATHNAME) != 0) {
+
+ if (fnmatch("TERM.*", entry->d_name, FNM_PATHNAME) != 0) {
continue;
}
/* +5 points to the character after the period */
- term_num = atoi(rd_entry->d_name+5);
+ term_num = atoi(entry->d_name+5);
gf_msg (this->name, GF_LOG_INFO, 0,
J_MSG_GENERIC,
- "%s => %d", rd_entry->d_name, term_num);
+ "%s => %d", entry->d_name, term_num);
if (term_num < 0) {
gf_msg (this->name, GF_LOG_ERROR, 0,
J_MSG_INVALID,
- "invalid term file name %s", rd_entry->d_name);
+ "invalid term file name %s", entry->d_name);
op_errno = EINVAL;
goto err;
}
@@ -1058,7 +1055,7 @@ jbr_get_terms (call_frame_t *frame, xlator_t *this)
goto err;
}
- sys_closedir (fp);
+ (void) sys_closedir (fp);
fp = NULL;
/*
@@ -1119,7 +1116,7 @@ jbr_get_terms (call_frame_t *frame, xlator_t *this)
err:
if (fp) {
- sys_closedir (fp);
+ (void) sys_closedir (fp);
}
if (my_xdata) {
dict_unref(my_xdata);