Browse code

clamd: scanstream: add mutex around gethostbyname

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

Tomasz Kojm authored on 2004/07/31 02:51:43
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Fri Jul 30 19:47:11 CEST 2004 (tk)
2
+----------------------------------
3
+  * clamd: scanstream: add mutex around gethostbyname
4
+
1 5
 Fri Jul 30 19:10:44 CEST 2004 (tk)
2 6
 ----------------------------------
3 7
   * libclamav: cli_bm_free: free b-m nodes (patch by Igor Brezac
... ...
@@ -34,6 +34,7 @@
34 34
 #include <arpa/inet.h>
35 35
 #include <netdb.h>
36 36
 #include <clamav.h>
37
+#include <pthread.h>
37 38
 
38 39
 #include "cfgparser.h"
39 40
 #include "others.h"
... ...
@@ -49,6 +50,8 @@
49 49
 dev_t procdev; /* /proc device */
50 50
 #endif
51 51
 
52
+pthread_mutex_t gh_mutex = PTHREAD_MUTEX_INITIALIZER;
53
+
52 54
 int checksymlink(const char *path)
53 55
 {
54 56
 	struct stat statbuf;
... ...
@@ -239,11 +242,14 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_node *root
239 239
 	server.sin_port = htons(port);
240 240
 
241 241
 	if((cpt = cfgopt(copt, "TCPAddr"))) {
242
-	    if ((he = gethostbyname(cpt->strarg)) == 0) {
242
+	    pthread_mutex_lock(&gh_mutex);
243
+	    if((he = gethostbyname(cpt->strarg)) == 0) {
243 244
 		logg("!gethostbyname(%s) error: %s\n", cpt->strarg);
244 245
 		mdprintf(odesc, "gethostbyname(%s) ERROR\n", cpt->strarg);
246
+		pthread_mutex_unlock(&gh_mutex);
245 247
 		return -1;
246 248
 	    }
249
+	    pthread_mutex_unlock(&gh_mutex);
247 250
 	    server.sin_addr = *(struct in_addr *) he->h_addr_list[0];
248 251
 	} else
249 252
 	    server.sin_addr.s_addr = INADDR_ANY;