|
|
a59965a |
From 15934e2c8123ee307574059d7c3f6a5916c054c9 Mon Sep 17 00:00:00 2001
|
|
|
a59965a |
From: Dave Reisner <dreisner@archlinux.org>
|
|
|
a59965a |
Date: Sat, 19 Apr 2014 13:22:35 -0400
|
|
|
a59965a |
Subject: [PATCH] implement a union to pad out file_handle
|
|
|
a59965a |
|
|
|
a59965a |
Cases where name_to_handle_at is used allocated the full struct to be
|
|
|
a59965a |
MAX_HANDLE_SZ, and assigned this size to handle_bytes. This is wrong
|
|
|
a59965a |
since handle_bytes should describe the length of the flexible array
|
|
|
a59965a |
member and not the whole struct.
|
|
|
a59965a |
|
|
|
a59965a |
Define a union type which includes sufficient padding to allow
|
|
|
a59965a |
assignment of MAX_HANDLE_SZ to be correct.
|
|
|
a59965a |
|
|
|
a59965a |
(cherry picked from commit 370c860f748d149097710dc7952a64f627db9de7)
|
|
|
a59965a |
|
|
|
a59965a |
Conflicts:
|
|
|
a59965a |
src/shared/util.h
|
|
|
a59965a |
|
|
|
a59965a |
(cherry picked from commit 91795825a093331ef136be1d630c5fcad299dfe8)
|
|
|
a59965a |
|
|
|
a59965a |
Conflicts:
|
|
|
a59965a |
src/libudev/libudev-monitor.c
|
|
|
a59965a |
src/shared/util.h
|
|
|
a59965a |
---
|
|
|
a59965a |
src/readahead/readahead-common.c | 6 ++----
|
|
|
a59965a |
src/shared/util.h | 6 ++++++
|
|
|
a59965a |
src/tmpfiles/tmpfiles.c | 11 ++++-------
|
|
|
a59965a |
3 files changed, 12 insertions(+), 11 deletions(-)
|
|
|
a59965a |
|
|
|
a59965a |
diff --git a/src/readahead/readahead-common.c b/src/readahead/readahead-common.c
|
|
|
a59965a |
index aea1fbe..1edf9cc 100644
|
|
|
a59965a |
--- a/src/readahead/readahead-common.c
|
|
|
a59965a |
+++ b/src/readahead/readahead-common.c
|
|
|
a59965a |
@@ -75,7 +75,7 @@ int fs_on_ssd(const char *p) {
|
|
|
a59965a |
if (major(st.st_dev) == 0) {
|
|
|
a59965a |
_cleanup_fclose_ FILE *f = NULL;
|
|
|
a59965a |
int mount_id;
|
|
|
a59965a |
- struct file_handle *h;
|
|
|
a59965a |
+ union file_handle_union h = { .handle.handle_bytes = MAX_HANDLE_SZ, };
|
|
|
a59965a |
|
|
|
a59965a |
/* Might be btrfs, which exposes "ssd" as mount flag if it is on ssd.
|
|
|
a59965a |
*
|
|
|
a59965a |
@@ -83,9 +83,7 @@ int fs_on_ssd(const char *p) {
|
|
|
a59965a |
* and then lookup the mount ID in mountinfo to find
|
|
|
a59965a |
* the mount options. */
|
|
|
a59965a |
|
|
|
a59965a |
- h = alloca(MAX_HANDLE_SZ);
|
|
|
a59965a |
- h->handle_bytes = MAX_HANDLE_SZ;
|
|
|
a59965a |
- r = name_to_handle_at(AT_FDCWD, p, h, &mount_id, AT_SYMLINK_FOLLOW);
|
|
|
a59965a |
+ r = name_to_handle_at(AT_FDCWD, p, &h.handle, &mount_id, AT_SYMLINK_FOLLOW);
|
|
|
a59965a |
if (r < 0)
|
|
|
a59965a |
return false;
|
|
|
a59965a |
|
|
|
a59965a |
diff --git a/src/shared/util.h b/src/shared/util.h
|
|
|
a59965a |
index 47a3dc9..a173885 100644
|
|
|
a59965a |
--- a/src/shared/util.h
|
|
|
a59965a |
+++ b/src/shared/util.h
|
|
|
a59965a |
@@ -22,6 +22,7 @@
|
|
|
a59965a |
***/
|
|
|
a59965a |
|
|
|
a59965a |
#include <alloca.h>
|
|
|
a59965a |
+#include <fcntl.h>
|
|
|
a59965a |
#include <inttypes.h>
|
|
|
a59965a |
#include <time.h>
|
|
|
a59965a |
#include <sys/time.h>
|
|
|
a59965a |
@@ -776,3 +777,8 @@ static inline void qsort_safe(void *base, size_t nmemb, size_t size,
|
|
|
a59965a |
qsort(base, nmemb, size, compar);
|
|
|
a59965a |
}
|
|
|
a59965a |
}
|
|
|
a59965a |
+
|
|
|
a59965a |
+union file_handle_union {
|
|
|
a59965a |
+ struct file_handle handle;
|
|
|
a59965a |
+ char padding[sizeof(struct file_handle) + MAX_HANDLE_SZ];
|
|
|
a59965a |
+};
|
|
|
a59965a |
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
|
|
|
a59965a |
index fb88acd..98d01a1 100644
|
|
|
a59965a |
--- a/src/tmpfiles/tmpfiles.c
|
|
|
a59965a |
+++ b/src/tmpfiles/tmpfiles.c
|
|
|
a59965a |
@@ -215,19 +215,16 @@ static bool unix_socket_alive(const char *fn) {
|
|
|
a59965a |
}
|
|
|
a59965a |
|
|
|
a59965a |
static int dir_is_mount_point(DIR *d, const char *subdir) {
|
|
|
a59965a |
- struct file_handle *h;
|
|
|
a59965a |
+ union file_handle_union h = { .handle.handle_bytes = MAX_HANDLE_SZ };
|
|
|
a59965a |
int mount_id_parent, mount_id;
|
|
|
a59965a |
int r_p, r;
|
|
|
a59965a |
|
|
|
a59965a |
- h = alloca(MAX_HANDLE_SZ);
|
|
|
a59965a |
-
|
|
|
a59965a |
- h->handle_bytes = MAX_HANDLE_SZ;
|
|
|
a59965a |
- r_p = name_to_handle_at(dirfd(d), ".", h, &mount_id_parent, 0);
|
|
|
a59965a |
+ r_p = name_to_handle_at(dirfd(d), ".", &h.handle, &mount_id_parent, 0);
|
|
|
a59965a |
if (r_p < 0)
|
|
|
a59965a |
r_p = -errno;
|
|
|
a59965a |
|
|
|
a59965a |
- h->handle_bytes = MAX_HANDLE_SZ;
|
|
|
a59965a |
- r = name_to_handle_at(dirfd(d), subdir, h, &mount_id, 0);
|
|
|
a59965a |
+ h.handle.handle_bytes = MAX_HANDLE_SZ;
|
|
|
a59965a |
+ r = name_to_handle_at(dirfd(d), subdir, &h.handle, &mount_id, 0);
|
|
|
a59965a |
if (r < 0)
|
|
|
a59965a |
r = -errno;
|
|
|
a59965a |
|