From f09670bd5682cb82f5b6ab512ea067f4c672b9ff Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 6 Jan 2011 14:51:37 +0000 Subject: [PATCH 3/3] dirent_buf_size: always demand at least sizeof(struct dirent) bytes As per http://womble.decadent.org.uk/readdir_r-advisory.html rev 4, d_name might not be the last member in struct dirent. --- dbus/dbus-sysdeps-util-unix.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff --git a/dbus/dbus-sysdeps-util-unix.c b/dbus/dbus-sysdeps-util-unix.c index 60a38d5..8a8f7a8 100644 --- a/dbus/dbus-sysdeps-util-unix.c +++ b/dbus/dbus-sysdeps-util-unix.c @@ -661,9 +661,16 @@ dirent_buf_size(DIR * dirp, size_t *size) name_max = 255; if (size) - *size = (size_t)offsetof(struct dirent, d_name) + name_max + 1; + { + *size = (size_t)offsetof(struct dirent, d_name) + name_max + 1; + + if (*size < sizeof(struct dirent)) + *size = sizeof(struct dirent); + } else - return FALSE; + { + return FALSE; + } return TRUE; } -- 1.7.2.3