From 370c860f748d149097710dc7952a64f627db9de7 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 19 Apr 2014 13:22:35 -0400 Subject: implement a union to pad out file_handle Cases where name_to_handle_at is used allocated the full struct to be MAX_HANDLE_SZ, and assigned this size to handle_bytes. This is wrong since handle_bytes should describe the length of the flexible array member and not the whole struct. Define a union type which includes sufficient padding to allow assignment of MAX_HANDLE_SZ to be correct. --- src/readahead/readahead-common.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/readahead') diff --git a/src/readahead/readahead-common.c b/src/readahead/readahead-common.c index 5ffa88b78a..49679fc834 100644 --- a/src/readahead/readahead-common.c +++ b/src/readahead/readahead-common.c @@ -75,7 +75,7 @@ int fs_on_ssd(const char *p) { if (major(st.st_dev) == 0) { _cleanup_fclose_ FILE *f = NULL; int mount_id; - struct file_handle *h; + union file_handle_union h = { .handle.handle_bytes = MAX_HANDLE_SZ, }; /* Might be btrfs, which exposes "ssd" as mount flag if it is on ssd. * @@ -83,9 +83,7 @@ int fs_on_ssd(const char *p) { * and then lookup the mount ID in mountinfo to find * the mount options. */ - h = alloca(MAX_HANDLE_SZ); - h->handle_bytes = MAX_HANDLE_SZ; - r = name_to_handle_at(AT_FDCWD, p, h, &mount_id, AT_SYMLINK_FOLLOW); + r = name_to_handle_at(AT_FDCWD, p, &h.handle, &mount_id, AT_SYMLINK_FOLLOW); if (r < 0) return false; -- cgit v1.2.3-54-g00ecf