From 7d5e9c0f60cddf01ec803012cbdc02d2f55b78c1 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 19 Sep 2012 22:21:09 +0200 Subject: util: define union dirent_storage and make use of it everywhere Make sure to allocate enough space for readdir_r(). https://bugzilla.redhat.com/show_bug.cgi?id=858754 --- src/shared/util.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/shared/util.c') diff --git a/src/shared/util.c b/src/shared/util.c index 69c9437db8..b48bad4c46 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -2956,9 +2956,10 @@ int dir_is_empty(const char *path) { return -errno; for (;;) { - struct dirent buf, *de; + struct dirent *de; + union dirent_storage buf; - r = readdir_r(d, &buf, &de); + r = readdir_r(d, &buf.de, &de); if (r > 0) return -r; @@ -3260,12 +3261,13 @@ int rm_rf_children_dangerous(int fd, bool only_dirs, bool honour_sticky, struct } for (;;) { - struct dirent buf, *de; + struct dirent *de; + union dirent_storage buf; bool is_dir, keep_around; struct stat st; int r; - r = readdir_r(d, &buf, &de); + r = readdir_r(d, &buf.de, &de); if (r != 0 && ret == 0) { ret = -r; break; @@ -4942,10 +4944,11 @@ int get_files_in_directory(const char *path, char ***list) { return -errno; for (;;) { - struct dirent buffer, *de; + struct dirent *de; + union dirent_storage buf; int k; - k = readdir_r(d, &buffer, &de); + k = readdir_r(d, &buf.de, &de); if (k != 0) { r = -k; goto finish; -- cgit v1.2.3-54-g00ecf