chiark / gitweb /
util: define union dirent_storage and make use of it everywhere
authorLennart Poettering <lennart@poettering.net>
Wed, 19 Sep 2012 20:21:09 +0000 (22:21 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 19 Sep 2012 20:21:09 +0000 (22:21 +0200)
Make sure to allocate enough space for readdir_r().

https://bugzilla.redhat.com/show_bug.cgi?id=858754

src/delta/delta.c
src/journal/journal-vacuum.c
src/journal/journald.c
src/journal/sd-journal.c
src/login/sd-login.c
src/shared/conf-files.c
src/shared/hwclock.c
src/shared/install.c
src/shared/util.c
src/shared/util.h
src/tmpfiles/tmpfiles.c

index eef6536b01f0897d9d182bc50d0f0f01b00e6b2c..803d2a7fc798bdc69b86b26e81b7a8b1959ec329 100644 (file)
@@ -176,11 +176,12 @@ static int enumerate_dir(Hashmap *top, Hashmap *bottom, const char *path) {
         }
 
         for (;;) {
-                struct dirent *de, buf;
+                struct dirent *de;
+                union dirent_storage buf;
                 int k;
                 char *p;
 
-                k = readdir_r(d, &buf, &de);
+                k = readdir_r(d, &buf.de, &de);
                 if (k != 0) {
                         r = -k;
                         goto finish;
index c89014653784d88e5634dc27a6d07ec8966ef7a8..ac16bdfcfd4890fbe603ebe38d572ec9ca4ba03c 100644 (file)
@@ -86,7 +86,8 @@ int journal_directory_vacuum(const char *directory, uint64_t max_use, uint64_t m
 
         for (;;) {
                 int k;
-                struct dirent buf, *de;
+                struct dirent *de;
+                union dirent_storage buf;
                 size_t q;
                 struct stat st;
                 char *p;
@@ -94,7 +95,7 @@ int journal_directory_vacuum(const char *directory, uint64_t max_use, uint64_t m
                 sd_id128_t seqnum_id;
                 bool have_seqnum;
 
-                k = readdir_r(d, &buf, &de);
+                k = readdir_r(d, &buf.de, &de);
                 if (k != 0) {
                         r = -k;
                         goto finish;
index 74c80f5a085a8b0b765656cfcb8c0ce4ca525127..164e1087d108879b70d9e7f59dfbc852e0120a1c 100644 (file)
@@ -141,9 +141,10 @@ static uint64_t available_space(Server *s) {
 
         for (;;) {
                 struct stat st;
-                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)
                         break;
 
index 2fa81727e049702bb0d5fae78decf37bded12275..acde84fe2d3138242b08ed1586df7ba1d9af3d5b 100644 (file)
@@ -1256,9 +1256,10 @@ static int add_directory(sd_journal *j, const char *prefix, const char *dirname)
         }
 
         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 || !de)
                         break;
 
@@ -1334,10 +1335,11 @@ static int add_root_directory(sd_journal *j, const char *p) {
         }
 
         for (;;) {
-                struct dirent buf, *de;
+                struct dirent *de;
+                union dirent_storage buf;
                 sd_id128_t id;
 
-                r = readdir_r(d, &buf, &de);
+                r = readdir_r(d, &buf.de, &de);
                 if (r != 0 || !de)
                         break;
 
index 82fe2ce3e338b744fa043f1e2a2162df60ca5410..45e3bb8dcd07c03451f106d235bfe8ee96f64b45 100644 (file)
@@ -651,11 +651,12 @@ _public_ int sd_get_uids(uid_t **users) {
                 return -errno;
 
         for (;;) {
-                struct dirent buffer, *de;
+                struct dirent *de;
+                union dirent_storage buf;
                 int k;
                 uid_t uid;
 
-                k = readdir_r(d, &buffer, &de);
+                k = readdir_r(d, &buf.de, &de);
                 if (k != 0) {
                         r = -k;
                         goto finish;
index 83e4cce15617ef89760b019c722127e52bf4e3a5..34b86293d3a246b9703a36eab41f8f020de4ff38 100644 (file)
@@ -39,7 +39,6 @@
 
 static int files_add(Hashmap *h, const char *path, const char *suffix) {
         DIR *dir;
-        struct dirent buffer, *de;
         int r = 0;
 
         dir = opendir(path);
@@ -50,10 +49,12 @@ static int files_add(Hashmap *h, const char *path, const char *suffix) {
         }
 
         for (;;) {
+                struct dirent *de;
+                union dirent_storage buf;
                 int k;
                 char *p;
 
-                k = readdir_r(dir, &buffer, &de);
+                k = readdir_r(dir, &buf.de, &de);
                 if (k != 0) {
                         r = -k;
                         goto finish;
index 67eb2eff8b0782c0a650f6418dc08527949d836f..b93855d95704388d4c0a2568b2c679d82fe507a5 100644 (file)
@@ -61,10 +61,11 @@ static int rtc_open(int flags) {
 
         for (;;) {
                 char *p, *v;
-                struct dirent buf, *de;
+                struct dirent *de;
+                union dirent_storage buf;
                 int r;
 
-                r = readdir_r(d, &buf, &de);
+                r = readdir_r(d, &buf.de, &de);
                 if (r != 0)
                         goto fallback;
 
index f30bf8317b802cb171193ec5f0ae6f862d48cf6c..a99c757ea87418574de1dd9060aaae09a023abcc 100644 (file)
@@ -201,7 +201,6 @@ static int remove_marked_symlinks_fd(
 
         int r = 0;
         DIR *d;
-        struct dirent buffer, *de;
 
         assert(remove_symlinks_to);
         assert(fd >= 0);
@@ -218,9 +217,11 @@ static int remove_marked_symlinks_fd(
         rewinddir(d);
 
         for (;;) {
+                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 = -errno;
                         break;
@@ -375,7 +376,6 @@ static int find_symlinks_fd(
 
         int r = 0;
         DIR *d;
-        struct dirent buffer, *de;
 
         assert(name);
         assert(fd >= 0);
@@ -391,8 +391,10 @@ static int find_symlinks_fd(
 
         for (;;) {
                 int k;
+                struct dirent *de;
+                union dirent_storage buf;
 
-                k = readdir_r(d, &buffer, &de);
+                k = readdir_r(d, &buf.de, &de);
                 if (k != 0) {
                         r = -errno;
                         break;
@@ -1906,7 +1908,6 @@ int unit_file_get_list(
                 return r;
 
         STRV_FOREACH(i, paths.unit_path) {
-                struct dirent buffer, *de;
                 const char *units_dir;
 
                 free(buf);
@@ -1934,9 +1935,11 @@ int unit_file_get_list(
                 }
 
                 for (;;) {
+                        struct dirent *de;
+                        union dirent_storage buffer;
                         UnitFileList *f;
 
-                        r = readdir_r(d, &buffer, &de);
+                        r = readdir_r(d, &buffer.de, &de);
                         if (r != 0) {
                                 r = -r;
                                 goto finish;
index 69c9437db83a826826435bcddbb04603cab02100..b48bad4c468a38068df2d504a7133d57e7ca4b8b 100644 (file)
@@ -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;
index 2429339f5bba3c3a46a1e521d902e3ceb1fc0a17..e5728bd87e275eee904a5d021a105f0211ad8765 100644 (file)
@@ -35,6 +35,7 @@
 #include <sys/stat.h>
 #include <dirent.h>
 #include <sys/resource.h>
+#include <stddef.h>
 
 #include "macro.h"
 
@@ -46,6 +47,12 @@ typedef struct dual_timestamp {
         usec_t monotonic;
 } dual_timestamp;
 
+union dirent_storage {
+        struct dirent de;
+        uint8_t storage[offsetof(struct dirent, d_name) +
+                        ((NAME_MAX + 1 + sizeof(long)) & ~(sizeof(long) - 1))];
+};
+
 #define MSEC_PER_SEC  1000ULL
 #define USEC_PER_SEC  1000000ULL
 #define USEC_PER_MSEC 1000ULL
index 5d0f571bea605f7a15838e2dbf643309911418b0..f10f90845e08d9337bf6c006896a35467fba295c 100644 (file)
@@ -551,12 +551,13 @@ static int recursive_relabel_children(Item *i, const char *path) {
                 return errno == ENOENT ? 0 : -errno;
 
         for (;;) {
-                struct dirent buf, *de;
+                struct dirent *de;
+                union dirent_storage buf;
                 bool is_dir;
                 int r;
                 char *entry_path;
 
-                r = readdir_r(d, &buf, &de);
+                r = readdir_r(d, &buf.de, &de);
                 if (r != 0) {
                         if (ret == 0)
                                 ret = -r;