git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@1050 77e5149b-7576-45b1-b177-96237e5ba77b
Tomasz Kojm authored on 2004/11/02 13:08:09... | ... |
@@ -1,3 +1,11 @@ |
1 |
+Tue Nov 2 04:58:43 CET 2004 (tk) |
|
2 |
+--------------------------------- |
|
3 |
+ * libclamav, clamd: readdir_r code: provide additional space (for at least |
|
4 |
+ NAME_MAX + 1 characters) in the d_name array on systems |
|
5 |
+ that don't define the d_name element sufficiently long |
|
6 |
+ (thanks to Andy Fiddaman <clam*fiddaman.net> for a |
|
7 |
+ pointer) |
|
8 |
+ |
|
1 | 9 |
Sun Oct 31 09:31:06 GMT 2004 (njh) |
2 | 10 |
---------------------------------- |
3 | 11 |
* libclamav: Improve the handling of blank filenames for attachments |
... | ... |
@@ -37,9 +37,8 @@ |
37 | 37 |
#include <pthread.h> |
38 | 38 |
|
39 | 39 |
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2) |
40 |
-#ifdef C_SOLARIS |
|
41 | 40 |
#include <limits.h> |
42 |
-#endif |
|
41 |
+#include <stddef.h> |
|
43 | 42 |
#endif |
44 | 43 |
|
45 | 44 |
#include "cfgparser.h" |
... | ... |
@@ -80,11 +79,10 @@ int dirscan(const char *dirname, const char **virname, unsigned long int *scanne |
80 | 80 |
DIR *dd; |
81 | 81 |
struct dirent *dent; |
82 | 82 |
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2) |
83 |
-#ifdef C_SOLARIS |
|
84 |
- char result[sizeof(struct dirent) + PATH_MAX + 1]; |
|
85 |
-#else |
|
86 |
- struct dirent result; |
|
87 |
-#endif |
|
83 |
+ union { |
|
84 |
+ struct dirent d; |
|
85 |
+ char b[offsetof(struct dirent, d_name) + NAME_MAX + 1]; |
|
86 |
+ } result; |
|
88 | 87 |
#endif |
89 | 88 |
struct stat statbuf; |
90 | 89 |
struct cfgstruct *cpt; |
... | ... |
@@ -107,9 +105,9 @@ int dirscan(const char *dirname, const char **virname, unsigned long int *scanne |
107 | 107 |
|
108 | 108 |
if((dd = opendir(dirname)) != NULL) { |
109 | 109 |
#ifdef HAVE_READDIR_R_3 |
110 |
- while(!readdir_r(dd, (struct dirent *) &result, &dent) && dent) { |
|
110 |
+ while(!readdir_r(dd, &result.d, &dent) && dent) { |
|
111 | 111 |
#elif defined(HAVE_READDIR_R_2) |
112 |
- while((dent = (struct dirent *) readdir_r(dd, (struct dirent *) &result))) { |
|
112 |
+ while((dent = (struct dirent *) readdir_r(dd, &result.d))) { |
|
113 | 113 |
#else |
114 | 114 |
while((dent = readdir(dd))) { |
115 | 115 |
#endif |
... | ... |
@@ -45,9 +45,8 @@ pthread_mutex_t cli_gentemp_mutex = PTHREAD_MUTEX_INITIALIZER; |
45 | 45 |
#endif |
46 | 46 |
|
47 | 47 |
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2) |
48 |
-#ifdef C_SOLARIS |
|
49 | 48 |
#include <limits.h> |
50 |
-#endif |
|
49 |
+#include <stddef.h> |
|
51 | 50 |
#endif |
52 | 51 |
|
53 | 52 |
#include "clamav.h" |
... | ... |
@@ -380,11 +379,10 @@ int cli_rmdirs(const char *dirname) |
380 | 380 |
DIR *dd; |
381 | 381 |
struct dirent *dent; |
382 | 382 |
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2) |
383 |
-#ifdef C_SOLARIS |
|
384 |
- char result[sizeof(struct dirent) + PATH_MAX + 1]; |
|
385 |
-#else |
|
386 |
- struct dirent result; |
|
387 |
-#endif |
|
383 |
+ union { |
|
384 |
+ struct dirent d; |
|
385 |
+ char b[offsetof(struct dirent, d_name) + NAME_MAX + 1]; |
|
386 |
+ } result; |
|
388 | 387 |
#endif |
389 | 388 |
struct stat maind, statbuf; |
390 | 389 |
char *fname; |
... | ... |
@@ -396,9 +394,9 @@ int cli_rmdirs(const char *dirname) |
396 | 396 |
if(!rmdir(dirname)) break; |
397 | 397 |
|
398 | 398 |
#ifdef HAVE_READDIR_R_3 |
399 |
- while(!readdir_r(dd, (struct dirent *) &result, &dent) && dent) { |
|
399 |
+ while(!readdir_r(dd, &result.d, &dent) && dent) { |
|
400 | 400 |
#elif defined(HAVE_READDIR_R_2) |
401 |
- while((dent = (struct dirent *) readdir_r(dd, (struct dirent *) &result))) { |
|
401 |
+ while((dent = (struct dirent *) readdir_r(dd, &result.d))) { |
|
402 | 402 |
#else |
403 | 403 |
while((dent = readdir(dd))) { |
404 | 404 |
#endif |
... | ... |
@@ -40,9 +40,8 @@ |
40 | 40 |
#include "defaults.h" |
41 | 41 |
|
42 | 42 |
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2) |
43 |
-#ifdef C_SOLARIS |
|
44 | 43 |
#include <limits.h> |
45 |
-#endif |
|
44 |
+#include <stddef.h> |
|
46 | 45 |
#endif |
47 | 46 |
|
48 | 47 |
/* TODO: clean up the code */ |
... | ... |
@@ -736,11 +735,10 @@ int cl_loaddbdir(const char *dirname, struct cl_node **root, unsigned int *signo |
736 | 736 |
DIR *dd; |
737 | 737 |
struct dirent *dent; |
738 | 738 |
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2) |
739 |
-#ifdef C_SOLARIS |
|
740 |
- char result[sizeof(struct dirent) + PATH_MAX + 1]; |
|
741 |
-#else |
|
742 |
- struct dirent result; |
|
743 |
-#endif |
|
739 |
+ union { |
|
740 |
+ struct dirent d; |
|
741 |
+ char b[offsetof(struct dirent, d_name) + NAME_MAX + 1]; |
|
742 |
+ } result; |
|
744 | 743 |
#endif |
745 | 744 |
char *dbfile; |
746 | 745 |
int ret; |
... | ... |
@@ -754,9 +752,9 @@ int cl_loaddbdir(const char *dirname, struct cl_node **root, unsigned int *signo |
754 | 754 |
cli_dbgmsg("Loading databases from %s\n", dirname); |
755 | 755 |
|
756 | 756 |
#ifdef HAVE_READDIR_R_3 |
757 |
- while(!readdir_r(dd, (struct dirent *) &result, &dent) && dent) { |
|
757 |
+ while(!readdir_r(dd, &result.d, &dent) && dent) { |
|
758 | 758 |
#elif defined(HAVE_READDIR_R_2) |
759 |
- while((dent = (struct dirent *) readdir_r(dd, (struct dirent *) &result))) { |
|
759 |
+ while((dent = (struct dirent *) readdir_r(dd, &result.d))) { |
|
760 | 760 |
#else |
761 | 761 |
while((dent = readdir(dd))) { |
762 | 762 |
#endif |
... | ... |
@@ -805,11 +803,10 @@ int cl_statinidir(const char *dirname, struct cl_stat *dbstat) |
805 | 805 |
DIR *dd; |
806 | 806 |
const struct dirent *dent; |
807 | 807 |
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2) |
808 |
-#ifdef C_SOLARIS |
|
809 |
- char result[sizeof(struct dirent) + PATH_MAX + 1]; |
|
810 |
-#else |
|
811 |
- struct dirent result; |
|
812 |
-#endif |
|
808 |
+ union { |
|
809 |
+ struct dirent d; |
|
810 |
+ char b[offsetof(struct dirent, d_name) + NAME_MAX + 1]; |
|
811 |
+ } result; |
|
813 | 812 |
#endif |
814 | 813 |
char *fname; |
815 | 814 |
|
... | ... |
@@ -831,9 +828,9 @@ int cl_statinidir(const char *dirname, struct cl_stat *dbstat) |
831 | 831 |
cli_dbgmsg("Stat()ing files in %s\n", dirname); |
832 | 832 |
|
833 | 833 |
#ifdef HAVE_READDIR_R_3 |
834 |
- while(!readdir_r(dd, (struct dirent *) &result, &dent) && dent) { |
|
834 |
+ while(!readdir_r(dd, &result.d, &dent) && dent) { |
|
835 | 835 |
#elif defined(HAVE_READDIR_R_2) |
836 |
- while((dent = (struct dirent *) readdir_r(dd, (struct dirent *) &result))) { |
|
836 |
+ while((dent = (struct dirent *) readdir_r(dd, &result.d))) { |
|
837 | 837 |
#else |
838 | 838 |
while((dent = readdir(dd))) { |
839 | 839 |
#endif |
... | ... |
@@ -868,11 +865,10 @@ int cl_statchkdir(const struct cl_stat *dbstat) |
868 | 868 |
DIR *dd; |
869 | 869 |
struct dirent *dent; |
870 | 870 |
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2) |
871 |
-#ifdef C_SOLARIS |
|
872 |
- char result[sizeof(struct dirent) + PATH_MAX + 1]; |
|
873 |
-#else |
|
874 |
- struct dirent result; |
|
875 |
-#endif |
|
871 |
+ union { |
|
872 |
+ struct dirent d; |
|
873 |
+ char b[offsetof(struct dirent, d_name) + NAME_MAX + 1]; |
|
874 |
+ } result; |
|
876 | 875 |
#endif |
877 | 876 |
struct stat sb; |
878 | 877 |
int i, found; |
... | ... |
@@ -892,9 +888,9 @@ int cl_statchkdir(const struct cl_stat *dbstat) |
892 | 892 |
cli_dbgmsg("Stat()ing files in %s\n", dbstat->dir); |
893 | 893 |
|
894 | 894 |
#ifdef HAVE_READDIR_R_3 |
895 |
- while(!readdir_r(dd, (struct dirent *) &result, &dent) && dent) { |
|
895 |
+ while(!readdir_r(dd, &result.d, &dent) && dent) { |
|
896 | 896 |
#elif defined(HAVE_READDIR_R_2) |
897 |
- while((dent = (struct dirent *) readdir_r(dd, (struct dirent *) &result))) { |
|
897 |
+ while((dent = (struct dirent *) readdir_r(dd, &result.d))) { |
|
898 | 898 |
#else |
899 | 899 |
while((dent = readdir(dd))) { |
900 | 900 |
#endif |
... | ... |
@@ -78,9 +78,8 @@ extern int cli_mbox(const char *dir, int desc, unsigned int options); /* FIXME * |
78 | 78 |
#endif |
79 | 79 |
|
80 | 80 |
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2) |
81 |
-#ifdef C_SOLARIS |
|
82 | 81 |
#include <limits.h> |
83 |
-#endif |
|
82 |
+#include <stddef.h> |
|
84 | 83 |
#endif |
85 | 84 |
|
86 | 85 |
|
... | ... |
@@ -759,11 +758,10 @@ static int cli_scandir(const char *dirname, const char **virname, long int *scan |
759 | 759 |
DIR *dd; |
760 | 760 |
struct dirent *dent; |
761 | 761 |
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2) |
762 |
-#ifdef C_SOLARIS |
|
763 |
- char result[sizeof(struct dirent) + PATH_MAX + 1]; |
|
764 |
-#else |
|
765 |
- struct dirent result; |
|
766 |
-#endif |
|
762 |
+ union { |
|
763 |
+ struct dirent d; |
|
764 |
+ char b[offsetof(struct dirent, d_name) + NAME_MAX + 1]; |
|
765 |
+ } result; |
|
767 | 766 |
#endif |
768 | 767 |
struct stat statbuf; |
769 | 768 |
char *fname; |
... | ... |
@@ -771,9 +769,9 @@ static int cli_scandir(const char *dirname, const char **virname, long int *scan |
771 | 771 |
|
772 | 772 |
if((dd = opendir(dirname)) != NULL) { |
773 | 773 |
#ifdef HAVE_READDIR_R_3 |
774 |
- while(!readdir_r(dd, (struct dirent *) &result, &dent) && dent) { |
|
774 |
+ while(!readdir_r(dd, &result.d, &dent) && dent) { |
|
775 | 775 |
#elif defined(HAVE_READDIR_R_2) |
776 |
- while((dent = (struct dirent *) readdir_r(dd, (struct dirent *) &result))) { |
|
776 |
+ while((dent = (struct dirent *) readdir_r(dd, &result.d))) { |
|
777 | 777 |
#else |
778 | 778 |
while((dent = readdir(dd))) { |
779 | 779 |
#endif |
... | ... |
@@ -823,11 +821,10 @@ static int cli_vba_scandir(const char *dirname, const char **virname, long int * |
823 | 823 |
DIR *dd; |
824 | 824 |
struct dirent *dent; |
825 | 825 |
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2) |
826 |
-#ifdef C_SOLARIS |
|
827 |
- char result[sizeof(struct dirent) + PATH_MAX + 1]; |
|
828 |
-#else |
|
829 |
- struct dirent result; |
|
830 |
-#endif |
|
826 |
+ union { |
|
827 |
+ struct dirent d; |
|
828 |
+ char b[offsetof(struct dirent, d_name) + NAME_MAX + 1]; |
|
829 |
+ } result; |
|
831 | 830 |
#endif |
832 | 831 |
struct stat statbuf; |
833 | 832 |
char *fname, *fullname; |
... | ... |
@@ -925,9 +922,9 @@ static int cli_vba_scandir(const char *dirname, const char **virname, long int * |
925 | 925 |
|
926 | 926 |
if((dd = opendir(dirname)) != NULL) { |
927 | 927 |
#ifdef HAVE_READDIR_R_3 |
928 |
- while(!readdir_r(dd, (struct dirent *) &result, &dent) && dent) { |
|
928 |
+ while(!readdir_r(dd, &result.d, &dent) && dent) { |
|
929 | 929 |
#elif defined(HAVE_READDIR_R_2) |
930 |
- while((dent = (struct dirent *) readdir_r(dd, (struct dirent *) &result))) { |
|
930 |
+ while((dent = (struct dirent *) readdir_r(dd, &result.d))) { |
|
931 | 931 |
#else |
932 | 932 |
while((dent = readdir(dd))) { |
933 | 933 |
#endif |