summaryrefslogtreecommitdiffstats
path: root/tools/gfind_missing_files
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 /tools/gfind_missing_files
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 'tools/gfind_missing_files')
-rw-r--r--tools/gfind_missing_files/gcrawler.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/tools/gfind_missing_files/gcrawler.c b/tools/gfind_missing_files/gcrawler.c
index 35772b5..02b644a 100644
--- a/tools/gfind_missing_files/gcrawler.c
+++ b/tools/gfind_missing_files/gcrawler.c
@@ -306,12 +306,12 @@ xworker_do_crawl (struct xwork *xwork, struct dirjob *job)
int ret = -1;
int boff;
int plen;
- struct dirent *result;
- char dbuf[512];
char *path = NULL;
struct dirjob *cjob = NULL;
struct stat statbuf = {0,};
- char gfid_path[4096] = {0,};
+ struct dirent *entry;
+ struct dirent scratch[2] = {{0,},};
+ char gfid_path[PATH_MAX] = {0,};
plen = strlen (job->dirname) + 256 + 2;
@@ -329,27 +329,29 @@ xworker_do_crawl (struct xwork *xwork, struct dirjob *job)
boff = sprintf (path, "%s/", job->dirname);
for (;;) {
- ret = readdir_r (dirp, (struct dirent *)dbuf, &result);
- if (ret) {
- err ("readdir_r(%s): %s\n", job->dirname,
- strerror (errno));
- goto out;
- }
-
- if (!result) /* EOF */
+ errno = 0;
+ entry = sys_readdir (dirp, scratch);
+ if (!entry || errno != 0) {
+ if (errno != 0) {
+ err ("readdir(%s): %s\n", job->dirname,
+ strerror (errno));
+ ret = errno;
+ goto out;
+ }
break;
+ }
- if (result->d_ino == 0)
+ if (entry->d_ino == 0)
continue;
- if (skip_name (job->dirname, result->d_name))
+ if (skip_name (job->dirname, entry->d_name))
continue;
/* It is sure that, children and grandchildren of .glusterfs
* are directories, just add them to global queue.
*/
- if (skip_stat (job, result->d_name)) {
- strncpy (path + boff, result->d_name, (plen-boff));
+ if (skip_stat (job, entry->d_name)) {
+ strncpy (path + boff, entry->d_name, (plen-boff));
cjob = dirjob_new (path, job);
if (!cjob) {
err ("dirjob_new(%s): %s\n",
@@ -361,13 +363,12 @@ xworker_do_crawl (struct xwork *xwork, struct dirjob *job)
continue;
}
- strcpy (gfid_path, slavemnt);
- strcat (gfid_path, "/.gfid/");
- strcat (gfid_path, result->d_name);
+ (void) snprintf (gfid_path, sizeof(gfid_path), "%s/.gfid/%s",
+ slavemnt, entry->d_name);
ret = sys_lstat (gfid_path, &statbuf);
if (ret && errno == ENOENT) {
- out ("%s\n", result->d_name);
+ out ("%s\n", entry->d_name);
BUMP (skipped_gfids);
}
@@ -381,7 +382,7 @@ xworker_do_crawl (struct xwork *xwork, struct dirjob *job)
ret = 0;
out:
if (dirp)
- sys_closedir (dirp);
+ (void) sys_closedir (dirp);
return ret;
}