diff options
author | Florian Weimer <fweimer@redhat.com> | 2013-12-19 12:05:41 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-12-21 18:35:55 -0500 |
commit | 3fd11280e82f590eaeda1e3945dafadf82cd8727 (patch) | |
tree | dc53aa5f7a83de5bf845b87ffefe3bdabc03b5b8 /src | |
parent | 4d993c8cb75aef0f4293e0b9e8f249dd0530b5d8 (diff) |
util: replace readdir_r with readdir
This fixes rm_rf_children_dangerous to detect errors during directory
reading. Previously, it could dereference an uninitialized pointer.
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/util.c | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index f59897105a..481c17245d 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -2306,7 +2306,6 @@ bool is_device_path(const char *path) { int dir_is_empty(const char *path) { _cleanup_closedir_ DIR *d; - int r; d = opendir(path); if (!d) @@ -2314,11 +2313,11 @@ int dir_is_empty(const char *path) { for (;;) { struct dirent *de; - union dirent_storage buf; - r = readdir_r(d, &buf.de, &de); - if (r > 0) - return -r; + errno = 0; + de = readdir(d); + if (!de && errno != 0) + return -errno; if (!de) return 1; @@ -2660,14 +2659,15 @@ int rm_rf_children_dangerous(int fd, bool only_dirs, bool honour_sticky, struct for (;;) { struct dirent *de; - union dirent_storage buf; bool is_dir, keep_around; struct stat st; int r; - r = readdir_r(d, &buf.de, &de); - if (r != 0 && ret == 0) { - ret = -r; + errno = 0; + de = readdir(d); + if (!de && errno != 0) { + if (ret == 0) + ret = -errno; break; } @@ -4485,13 +4485,11 @@ int get_files_in_directory(const char *path, char ***list) { for (;;) { struct dirent *de; - union dirent_storage buf; - int k; - k = readdir_r(d, &buf.de, &de); - assert(k >= 0); - if (k > 0) - return -k; + errno = 0; + de = readdir(d); + if (!de && errno != 0) + return -errno; if (!de) break; @@ -5617,15 +5615,14 @@ int on_ac_power(void) { for (;;) { struct dirent *de; - union dirent_storage buf; _cleanup_close_ int fd = -1, device = -1; char contents[6]; ssize_t n; - int k; - k = readdir_r(d, &buf.de, &de); - if (k != 0) - return -k; + errno = 0; + de = readdir(d); + if (!de && errno != 0) + return -errno; if (!de) break; |