Browse code

* clamd/server-th.c: error handling * libclamav/ole2_extract.c: change struct pack code to support old versions of gcc - for the last time I hope.

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@390 77e5149b-7576-45b1-b177-96237e5ba77b

Trog authored on 2004/03/10 22:31:32
Showing 3 changed files
... ...
@@ -1,3 +1,9 @@
1
+Wed Mar 10 12:58:55 GMT 2004 (trog)
2
+-----------------------------------
3
+  * clamd/server-th.c: error handling
4
+  * libclamav/ole2_extract.c: change struct pack code to support
5
+	old versions of gcc - for the last time I hope.
6
+
1 7
 Wed Mar 10 11:40:14 GMT 2004 (njh)
2 8
 ----------------------------------
3 9
   * clamav-milter:	Use new HAVE_STRERROR_R rather than TARGET_OS_SOLARIS
... ...
@@ -423,7 +423,11 @@ int acceptloop_th(int socketd, struct cl_node *root, const struct cfgstruct *cop
423 423
 		client_conn->root = root;
424 424
 		client_conn->limits = &limits;
425 425
 		client_conn->mainpid = mainpid;
426
-		thrmgr_dispatch(thr_pool, client_conn);
426
+		if (!thrmgr_dispatch(thr_pool, client_conn)) {
427
+		    close(client_conn->sd);
428
+		    free(client_conn);
429
+		    logg("!thread dispatch failed");
430
+		}
427 431
 	}
428 432
 
429 433
 	pthread_mutex_lock(&exit_mutex);
... ...
@@ -37,10 +37,14 @@
37 37
 #include "cltypes.h"
38 38
 #include "others.h"
39 39
 
40
+#ifndef FALSE
40 41
 #define FALSE (0)
41 42
 #define TRUE (1)
43
+#endif
42 44
 
45
+#ifndef MIN
43 46
 #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
47
+#endif
44 48
 
45 49
 #if WORDS_BIGENDIAN == 0
46 50
 #define ole2_endian_convert_16(v)	(v)
... ...
@@ -71,55 +75,55 @@ static uint32_t ole2_endian_convert_32(uint32_t v)
71 71
 
72 72
 typedef struct ole2_header_tag
73 73
 {
74
-	unsigned char magic[8];			/* should be: 0xd0cf11e0a1b11ae1 */
75
-	unsigned char clsid[16];
76
-	uint16_t minor_version;
77
-	uint16_t dll_version;
78
-	int16_t byte_order;			/* -2=intel */
74
+	unsigned char magic[8] __attribute__ ((packed));		/* should be: 0xd0cf11e0a1b11ae1 */
75
+	unsigned char clsid[16] __attribute__ ((packed));
76
+	uint16_t minor_version __attribute__ ((packed));
77
+	uint16_t dll_version __attribute__ ((packed));
78
+	int16_t byte_order __attribute__ ((packed));			/* -2=intel */
79 79
 
80
-	uint16_t log2_big_block_size;		/* usually 9 (2^9 = 512) */
81
-	uint32_t log2_small_block_size;		/* usually 6 (2^6 = 128) */
80
+	uint16_t log2_big_block_size __attribute__ ((packed));		/* usually 9 (2^9 = 512) */
81
+	uint32_t log2_small_block_size __attribute__ ((packed));	/* usually 6 (2^6 = 128) */
82 82
 
83
-	int32_t reserved[2];
84
-	int32_t bat_count;
85
-	int32_t prop_start;
83
+	int32_t reserved[2] __attribute__ ((packed));
84
+	int32_t bat_count __attribute__ ((packed));
85
+	int32_t prop_start __attribute__ ((packed));
86 86
 
87
-	uint32_t signature;
88
-	uint32_t sbat_cutoff;			/* cutoff for files held in small blocks (4096) */
87
+	uint32_t signature __attribute__ ((packed));
88
+	uint32_t sbat_cutoff __attribute__ ((packed));			/* cutoff for files held in small blocks (4096) */
89 89
 
90
-	int32_t sbat_start;
91
-	int32_t sbat_block_count;
92
-	int32_t xbat_start;
93
-	int32_t xbat_count;
94
-	int32_t bat_array[109];
90
+	int32_t sbat_start __attribute__ ((packed));
91
+	int32_t sbat_block_count __attribute__ ((packed));
92
+	int32_t xbat_start __attribute__ ((packed));
93
+	int32_t xbat_count __attribute__ ((packed));
94
+	int32_t bat_array[109] __attribute__ ((packed));
95 95
 
96 96
 	/* not part of the ole2 header, but stuff we need in order to decode */
97 97
 	/* must take account of the size of variables below here when
98 98
 	   reading the header */
99
-	int32_t sbat_root_start;
100
-} __attribute__ ((packed)) ole2_header_t;
99
+	int32_t sbat_root_start __attribute__ ((packed));
100
+} ole2_header_t;
101 101
 
102 102
 typedef struct property_tag
103 103
 {
104
-	unsigned char name[64];			/* in unicode */
105
-	int16_t name_size;
106
-	unsigned char type;			/* 1=dir 2=file 5=root */
107
-	unsigned char color;			/* black or red */
108
-	int32_t prev;
109
-	int32_t next;
110
-	int32_t child;
111
-
112
-	unsigned char clsid[16];
113
-	uint32_t user_flags;
114
-
115
-	uint32_t create_lowdate;
116
-	uint32_t create_highdate;
117
-	uint32_t mod_lowdate;
118
-	uint32_t mod_highdate;
119
-	int32_t start_block;
120
-	int32_t size;
121
-	unsigned char reserved[4];
122
-} __attribute__ ((packed)) property_t;
104
+	unsigned char name[64] __attribute__ ((packed));		/* in unicode */
105
+	int16_t name_size __attribute__ ((packed));
106
+	unsigned char type __attribute__ ((packed));			/* 1=dir 2=file 5=root */
107
+	unsigned char color __attribute__ ((packed));			/* black or red */
108
+	int32_t prev __attribute__ ((packed));
109
+	int32_t next __attribute__ ((packed));
110
+	int32_t child __attribute__ ((packed));
111
+
112
+	unsigned char clsid[16] __attribute__ ((packed));
113
+	uint32_t user_flags __attribute__ ((packed));
114
+
115
+	uint32_t create_lowdate __attribute__ ((packed));
116
+	uint32_t create_highdate __attribute__ ((packed));
117
+	uint32_t mod_lowdate __attribute__ ((packed));
118
+	uint32_t mod_highdate __attribute__ ((packed));
119
+	int32_t start_block __attribute__ ((packed));
120
+	int32_t size __attribute__ ((packed));
121
+	unsigned char reserved[4] __attribute__ ((packed));
122
+} property_t;
123 123
 
124 124
 #ifdef HAVE_PRAGMA_PACK
125 125
 #pragma pack()
... ...
@@ -127,11 +131,10 @@ typedef struct property_tag
127 127
 
128 128
 unsigned char magic_id[] = { 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1};
129 129
 
130
-
131 130
 /* Function: readn
132 131
 	Try hard to read the requested number of bytes
133 132
 */
134
-int readn(int fd, void *buff, unsigned int count)
133
+static int readn(int fd, void *buff, unsigned int count)
135 134
 {
136 135
 	int retval;
137 136
 	unsigned int todo;
... ...
@@ -158,7 +161,7 @@ int readn(int fd, void *buff, unsigned int count)
158 158
 /* Function: writen
159 159
 	Try hard to write the specified number of bytes
160 160
 */
161
-int writen(int fd, void *buff, unsigned int count)
161
+static int writen(int fd, void *buff, unsigned int count)
162 162
 {
163 163
 	int retval;
164 164
 	unsigned int todo;
... ...
@@ -179,7 +182,7 @@ int writen(int fd, void *buff, unsigned int count)
179 179
 	return count;
180 180
 }
181 181
 
182
-char *get_property_name(char *name, int size)
182
+static char *get_property_name(char *name, int size)
183 183
 {
184 184
 	int i, j;
185 185
 	char *newname;
... ...
@@ -212,8 +215,8 @@ char *get_property_name(char *name, int size)
212 212
 	}
213 213
 	return newname;
214 214
 }
215
-                                                                                                                                              
216
-void print_property_name(char *pname, int size)
215
+
216
+static void print_property_name(char *pname, int size)
217 217
 {
218 218
         char *name;
219 219
                                                                                                                                               
... ...
@@ -226,7 +229,7 @@ void print_property_name(char *pname, int size)
226 226
         return;
227 227
 }
228 228
 
229
-void print_ole2_property(property_t *property)
229
+static void print_ole2_property(property_t *property)
230 230
 {
231 231
 	if (property->name_size > 64) {
232 232
                 cli_dbgmsg("[err name len: %d]\n", property->name_size);
... ...
@@ -259,7 +262,7 @@ void print_ole2_property(property_t *property)
259 259
 	cli_dbgmsg(" %d %x\n", property->size, property->user_flags);
260 260
 }
261 261
 
262
-void print_ole2_header(ole2_header_t *hdr)
262
+static void print_ole2_header(ole2_header_t *hdr)
263 263
 {
264 264
 	int i;
265 265
 	
... ...
@@ -294,7 +297,7 @@ void print_ole2_header(ole2_header_t *hdr)
294 294
 	return;
295 295
 }
296 296
 
297
-int ole2_read_block(int fd, ole2_header_t *hdr, void *buff, int32_t blockno)
297
+static int ole2_read_block(int fd, ole2_header_t *hdr, void *buff, int32_t blockno)
298 298
 {
299 299
 	off_t offset;
300 300
 
... ...
@@ -313,7 +316,7 @@ int ole2_read_block(int fd, ole2_header_t *hdr, void *buff, int32_t blockno)
313 313
 	return TRUE;
314 314
 }
315 315
 
316
-int32_t ole2_get_next_bat_block(int fd, ole2_header_t *hdr, int32_t current_block)
316
+static int32_t ole2_get_next_bat_block(int fd, ole2_header_t *hdr, int32_t current_block)
317 317
 {
318 318
 	int32_t bat_array_index;
319 319
 	uint32_t bat[128];
... ...
@@ -334,7 +337,7 @@ int32_t ole2_get_next_bat_block(int fd, ole2_header_t *hdr, int32_t current_bloc
334 334
 	return ole2_endian_convert_32(bat[current_block-(bat_array_index * 128)]);
335 335
 }
336 336
 
337
-int32_t ole2_get_next_xbat_block(int fd, ole2_header_t *hdr, int32_t current_block)
337
+static int32_t ole2_get_next_xbat_block(int fd, ole2_header_t *hdr, int32_t current_block)
338 338
 {
339 339
 	int32_t xbat_index, xbat_block_index, bat_index, bat_blockno;
340 340
 	uint32_t xbat[128], bat[128];
... ...
@@ -373,7 +376,7 @@ int32_t ole2_get_next_xbat_block(int fd, ole2_header_t *hdr, int32_t current_blo
373 373
 	return ole2_endian_convert_32(bat[bat_index]);
374 374
 }
375 375
 
376
-int32_t ole2_get_next_block_number(int fd, ole2_header_t *hdr, int32_t current_block)
376
+static int32_t ole2_get_next_block_number(int fd, ole2_header_t *hdr, int32_t current_block)
377 377
 {
378 378
 	if (current_block < 0) {
379 379
 		return -1;
... ...
@@ -386,7 +389,7 @@ int32_t ole2_get_next_block_number(int fd, ole2_header_t *hdr, int32_t current_b
386 386
 	}
387 387
 }
388 388
 
389
-int32_t ole2_get_next_sbat_block(int fd, ole2_header_t *hdr, int32_t current_block)
389
+static int32_t ole2_get_next_sbat_block(int fd, ole2_header_t *hdr, int32_t current_block)
390 390
 {
391 391
 	int32_t iter, current_bat_block;
392 392
 	uint32_t sbat[128];
... ...
@@ -408,7 +411,7 @@ int32_t ole2_get_next_sbat_block(int fd, ole2_header_t *hdr, int32_t current_blo
408 408
 }
409 409
 
410 410
 /* Retrieve the block containing the data for the given sbat index */
411
-int32_t ole2_get_sbat_data_block(int fd, ole2_header_t *hdr, void *buff, int32_t sbat_index)
411
+static int32_t ole2_get_sbat_data_block(int fd, ole2_header_t *hdr, void *buff, int32_t sbat_index)
412 412
 {
413 413
 	int32_t block_count, current_block;
414 414
 
... ...
@@ -431,12 +434,11 @@ int32_t ole2_get_sbat_data_block(int fd, ole2_header_t *hdr, void *buff, int32_t
431 431
 	   containing the entry for the required small block */
432 432
 
433 433
 	return(ole2_read_block(fd, hdr, buff, current_block));
434
-
435 434
 }
436 435
 
437 436
 /* Read the property tree.
438 437
    It is read as just an array rather than a tree */
439
-void ole2_read_property_tree(int fd, ole2_header_t *hdr, const char *dir,
438
+static void ole2_read_property_tree(int fd, ole2_header_t *hdr, const char *dir,
440 439
 				int (*handler)(int fd, ole2_header_t *hdr, property_t *prop, const char *dir))
441 440
 {
442 441
 	property_t prop_block[4];
... ...
@@ -486,17 +488,8 @@ void ole2_read_property_tree(int fd, ole2_header_t *hdr, const char *dir,
486 486
 	return;
487 487
 }
488 488
 
489
-/* Callback handlers
490
-   These are called for each entry in the container (property tree) */
491
-
492
-/* Null Handler - doesn't do anything */
493
-int handler_null(int fd, ole2_header_t *hdr, property_t *prop, const char *dir)
494
-{
495
-	return TRUE;
496
-}
497
-
498 489
 /* Write file Handler - write the contents of the entry to a file */
499
-int handler_writefile(int fd, ole2_header_t *hdr, property_t *prop, const char *dir)
490
+static int handler_writefile(int fd, ole2_header_t *hdr, property_t *prop, const char *dir)
500 491
 {
501 492
 	unsigned char buff[(1 << hdr->log2_big_block_size)];
502 493
 	int32_t current_block, ofd, len, offset;
... ...
@@ -573,7 +566,7 @@ int handler_writefile(int fd, ole2_header_t *hdr, property_t *prop, const char *
573 573
 	return TRUE;
574 574
 }
575 575
 
576
-int ole2_read_header(int fd, ole2_header_t *hdr)
576
+static int ole2_read_header(int fd, ole2_header_t *hdr)
577 577
 {
578 578
 	int i;
579 579