From b3a280d5af9d06783d2698bd434940de94ab0fda Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 23 Aug 2013 11:45:35 -0700 Subject: [PATCH] os: make readdir_r buffers larger PATH_MAX isn't quite big enough. Backport: dumpling, cuttlefish, bobtail Signed-off-by: Sage Weil (cherry picked from commit 99a2ff7da99f8cf70976f05d4fe7aa28dd7afae5) --- src/os/FlatIndex.cc | 5 +++-- src/os/LFNIndex.cc | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/os/FlatIndex.cc b/src/os/FlatIndex.cc index f4a5ce3ab7dcd..db46750e41118 100644 --- a/src/os/FlatIndex.cc +++ b/src/os/FlatIndex.cc @@ -387,7 +387,8 @@ int FlatIndex::collection_list_partial(const hobject_t &start, } int FlatIndex::collection_list(vector *ls) { - char dir_name[PATH_MAX], buf[PATH_MAX], new_name[PATH_MAX]; + char buf[offsetof(struct dirent, d_name) + PATH_MAX + 1]; + char dir_name[PATH_MAX], new_name[PATH_MAX]; strncpy(dir_name, base_path.c_str(), sizeof(dir_name)); dir_name[sizeof(dir_name)-1]='\0'; @@ -399,7 +400,7 @@ int FlatIndex::collection_list(vector *ls) { vector< pair > inolist; struct dirent *de; - while (::readdir_r(dir, (struct dirent*)buf, &de) == 0) { + while (::readdir_r(dir, (struct dirent *)buf, &de) == 0) { if (!de) break; // parse diff --git a/src/os/LFNIndex.cc b/src/os/LFNIndex.cc index 09d0f02267f8c..029e8ad8197e6 100644 --- a/src/os/LFNIndex.cc +++ b/src/os/LFNIndex.cc @@ -378,7 +378,7 @@ int LFNIndex::list_objects(const vector &to_list, int max_objs, long *handle, map *out) { string to_list_path = get_full_path_subdir(to_list); DIR *dir = ::opendir(to_list_path.c_str()); - char buf[PATH_MAX]; + char buf[offsetof(struct dirent, d_name) + PATH_MAX + 1]; int r; if (!dir) { return -errno; @@ -438,7 +438,7 @@ int LFNIndex::list_subdirs(const vector &to_list, set *out) { string to_list_path = get_full_path_subdir(to_list); DIR *dir = ::opendir(to_list_path.c_str()); - char buf[PATH_MAX]; + char buf[offsetof(struct dirent, d_name) + PATH_MAX + 1]; if (!dir) return -errno; -- 2.39.5