diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-10-19 14:54:42 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-10-19 14:55:02 +0100 |
commit | 82bb01e1f894af9777625bfbfb9049e5083e0e56 (patch) | |
tree | 43fb7b3435dea59fcaf1f88626ead5a687f70968 /src/client | |
parent | e139768a0dae674fa42528fe4297d67e8203eacb (diff) | |
download | rspamd-82bb01e1f894af9777625bfbfb9049e5083e0e56.tar.gz rspamd-82bb01e1f894af9777625bfbfb9049e5083e0e56.zip |
[Fix] Another try to deal with posix idiotizm
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/rspamc.c | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/src/client/rspamc.c b/src/client/rspamc.c index 400c4c59b..c7068ae8d 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -1411,6 +1411,39 @@ rspamc_process_input (struct event_base *ev_base, struct rspamc_command *cmd, g_free (hostbuf); } +static gsize +rspamd_dirent_size (DIR * dirp) +{ + goffset name_max; + gsize name_end; + +#if defined(HAVE_FPATHCONF) && defined(HAVE_DIRFD) \ + && defined(_PC_NAME_MAX) + name_max = fpathconf (dirfd (dirp), _PC_NAME_MAX); + + +# if defined(NAME_MAX) + if (name_max == -1) { + name_max = (NAME_MAX > 255) ? NAME_MAX : 255; + } +# else + if (name_max == -1) { + return (size_t)(-1); + } +# endif +#else +# if defined(NAME_MAX) + name_max = (NAME_MAX > 255) ? NAME_MAX : 255; +# else +# error "buffer size for readdir_r cannot be determined" +# endif +#endif + + name_end = G_STRUCT_OFFSET (struct dirent, d_name) + name_max + 1; + + return (name_end > sizeof (struct dirent) ? name_end : sizeof(struct dirent)); +} + static void rspamc_process_dir (struct event_base *ev_base, struct rspamc_command *cmd, const gchar *name, GQueue *attrs) @@ -1422,19 +1455,14 @@ rspamc_process_dir (struct event_base *ev_base, struct rspamc_command *cmd, FILE *in; struct stat st; gboolean is_reg, is_dir; - gsize name_max, len; + gsize len; d = opendir (name); if (d != NULL) { /* Portably allocate struct direntry */ - name_max = pathconf (name, _PC_NAME_MAX); - - if (name_max == -1) { - name_max = PATH_MAX; - } - - len = G_STRUCT_OFFSET (struct dirent, d_name) + name_max + 1; + len = rspamd_dirent_size (d); + g_assert (len != (gsize)-1); entry = g_malloc0 (len); while (readdir_r (d, entry, pentry) == 0) { |