From 1e0fe24faaa70d8ecfcc3d051d0e9dc75b744a9d Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 6 Jan 2011 14:48:06 +0000 Subject: [PATCH 1/3] dirent_buf_size: always assume readdir_r needs at least 255 bytes HP-UX apparently defines NAME_MAX too small. Sigh. --- dbus/dbus-sysdeps-util-unix.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/dbus/dbus-sysdeps-util-unix.c b/dbus/dbus-sysdeps-util-unix.c index 00705b3..c01b2a7 100644 --- a/dbus/dbus-sysdeps-util-unix.c +++ b/dbus/dbus-sysdeps-util-unix.c @@ -615,6 +615,9 @@ _dbus_directory_open (const DBusString *filename, * If you use autoconf, include fpathconf and dirfd in your * AC_CHECK_FUNCS list. Otherwise use some other method to detect * and use them where available. + * + * Read and understand http://womble.decadent.org.uk/readdir_r-advisory.html + * before modifying this function! */ static dbus_bool_t dirent_buf_size(DIR * dirp, size_t *size) @@ -643,6 +646,12 @@ dirent_buf_size(DIR * dirp, size_t *size) # error "buffer size for readdir_r cannot be determined" # endif # endif + + /* Don't trust values of NAME_MAX less than 255. According to + * "readdir_r considered harmful", HP-UX incorrectly defines it smaller. */ + if (name_max < 255) + name_max = 255; + if (size) *size = (size_t)offsetof(struct dirent, d_name) + name_max + 1; else -- 1.7.2.3