From e24e2eb78b57ccba5769448093de7fa884e5943f Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Fri, 11 Jun 2021 14:05:19 +0200 Subject: [PATCH] revert of https://github.com/clicon/clixon/pull/238 --- lib/src/clixon_file.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/src/clixon_file.c b/lib/src/clixon_file.c index c31a0e7a..b2ac679f 100644 --- a/lib/src/clixon_file.c +++ b/lib/src/clixon_file.c @@ -104,7 +104,6 @@ clicon_file_dirent(const char *dir, DIR *dirp; int res; int nent; - int direntStructSize; regex_t re; char errbuf[128]; char filename[MAXPATHLEN]; @@ -112,8 +111,11 @@ clicon_file_dirent(const char *dir, struct dirent *dent; struct dirent *tmp; struct dirent *new = NULL; - struct dirent *dvecp = NULL; +#if 0 /* revert of https://github.com/clicon/clixon/pull/238 */ + int direntStructSize; +#endif + clicon_debug(1, "%s", __FUNCTION__); *ent = NULL; nent = 0; if (regexp && (res = regcomp(&re, regexp, REG_EXTENDED)) != 0) { @@ -145,13 +147,23 @@ clicon_file_dirent(const char *dir, if ((type & st.st_mode) == 0) continue; } +#if 0 /* revert of https://github.com/clicon/clixon/pull/238 */ direntStructSize = offsetof(struct dirent, d_name) + strlen(dent->d_name) + 1; + clicon_debug(1, "%s %u %u %lu", __FUNCTION__, nent, direntStructSize, sizeof(struct dirent)); if ((tmp = realloc(new, (nent+1)*direntStructSize)) == NULL) { +#else + if ((tmp = realloc(new, (nent+1)*sizeof(struct dirent))) == NULL) { +#endif clicon_err(OE_UNIX, errno, "realloc"); goto quit; } new = tmp; - memcpy(&new[nent], dent, direntStructSize); +#if 0 /* revert of https://github.com/clicon/clixon/pull/238 */ + clicon_debug(1, "%s memcpy(%p %p %u", __FUNCTION__, &new[nent], dent, direntStructSize); + memcpy(&new[nent], dent, direntStructSize); /* XXX Invalid write of size 8 */ +#else + memcpy(&new[nent], dent, sizeof(*dent)); +#endif nent++; } /* while */