summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip@tecnocode.co.uk>2023-10-04 08:19:01 +0000
committerPhilip Withnall <philip@tecnocode.co.uk>2023-10-04 08:19:01 +0000
commite272f135da0c2fdbb9329b87e10e4d05bfff9de8 (patch)
tree5bef8a0f7420be20d743b93b879a6f81dac27580
parent13bc82d01676639e0a60f5bfc01efdac37db7b76 (diff)
parent877e277b51a765923c1a91199a52295b13128aa9 (diff)
downloadglib-e272f135da0c2fdbb9329b87e10e4d05bfff9de8.tar.gz
Merge branch 'backport-3582-dirent-alignment-glib-2-76' into 'glib-2-76'
Backport !3582 “Buffer needs to be aligned correctly to receive linux_dirent64.” to glib-2-76 See merge request GNOME/glib!3615
-rw-r--r--glib/gspawn.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/glib/gspawn.c b/glib/gspawn.c
index 581729733..6f18c80dc 100644
--- a/glib/gspawn.c
+++ b/glib/gspawn.c
@@ -1441,15 +1441,22 @@ safe_fdwalk (int (*cb)(void *data, int fd), void *data)
int dir_fd = open ("/proc/self/fd", O_RDONLY | O_DIRECTORY);
if (dir_fd >= 0)
{
- char buf[4096];
+ /* buf needs to be aligned correctly to receive linux_dirent64.
+ * C11 has _Alignof for this purpose, but for now a
+ * union serves the same purpose. */
+ union
+ {
+ char buf[4096];
+ struct linux_dirent64 alignment;
+ } u;
int pos, nread;
struct linux_dirent64 *de;
- while ((nread = syscall (SYS_getdents64, dir_fd, buf, sizeof(buf))) > 0)
+ while ((nread = syscall (SYS_getdents64, dir_fd, u.buf, sizeof (u.buf))) > 0)
{
for (pos = 0; pos < nread; pos += de->d_reclen)
{
- de = (struct linux_dirent64 *)(buf + pos);
+ de = (struct linux_dirent64 *) (u.buf + pos);
fd = filename_to_fd (de->d_name);
if (fd < 0 || fd == dir_fd)