Browse code

Mutex gethostbyname result

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

Nigel Horne authored on 2004/07/22 06:26:09
Showing 3 changed files
... ...
@@ -1,3 +1,8 @@
1
+Wed Jul 21 22:23:58 BST 2004 (njh)
2
+----------------------------------
3
+  * clamav-milter:	Add mutex around gethostbyname
4
+
5
+
1 6
 Wed Jul 21 23:18:51 CEST 2004 (tk)
2 7
 ----------------------------------
3 8
   * configure: test for gethostbyname_r
... ...
@@ -435,6 +435,8 @@ Changes
435 435
 0.74c	14/7/04	Added --dont-wait
436 436
 		Added --advisory
437 437
 0.74d	18/7/04	Added sanity check in clamfi_connect
438
+0.74e	21/7/04	Fixed thread unsafe code causing problems with multi-CPU
439
+		machines running Solaris
438 440
 
439 441
 BUG REPORTS
440 442
 
... ...
@@ -26,6 +26,9 @@
26 26
  *
27 27
  * Change History:
28 28
  * $Log: clamav-milter.c,v $
29
+ * Revision 1.106  2004/07/21 21:23:29  nigelhorne
30
+ * Mutex gethostbyname result
31
+ *
29 32
  * Revision 1.105  2004/07/21 17:46:06  nigelhorne
30 33
  * Added note about needing MILTER support in sendmail
31 34
  *
... ...
@@ -326,9 +329,9 @@
326 326
  * Revision 1.6  2003/09/28 16:37:23  nigelhorne
327 327
  * Added -f flag use MaxThreads if --max-children not set
328 328
  */
329
-static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.105 2004/07/21 17:46:06 nigelhorne Exp $";
329
+static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.106 2004/07/21 21:23:29 nigelhorne Exp $";
330 330
 
331
-#define	CM_VERSION	"0.74d"
331
+#define	CM_VERSION	"0.74e"
332 332
 
333 333
 /*#define	CONFDIR	"/usr/local/etc"*/
334 334
 
... ...
@@ -1499,7 +1502,15 @@ clamfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
1499 1499
 	 */
1500 1500
 	if(strncasecmp(port, "inet:", 5) == 0) {
1501 1501
 		const char *hostmail;
1502
-		const struct hostent *hp = NULL;
1502
+#ifdef	GETHOSTBYNAME_R
1503
+		struct hostent *hp, hostent;
1504
+		char buf[BUFSIZ];
1505
+		int ret;
1506
+#else
1507
+		const struct hostent *hp2, *hp;
1508
+		struct hostent hostent;
1509
+		static pthread_mutex_t hostent_mutex = PTHREAD_MUTEX_INITIALIZER;
1510
+#endif
1503 1511
 
1504 1512
 		/*
1505 1513
 		 * Using TCP/IP for the sendmail->clamav-milter connection
... ...
@@ -1510,14 +1521,27 @@ clamfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
1510 1510
 			hostmail = "unknown";
1511 1511
 		}
1512 1512
 
1513
-		if((hp = gethostbyname(hostmail)) == NULL) {
1513
+#ifdef	GETHOSTBYNAME_R
1514
+		if(gethostbyname_r(hostmail, &hostent, buf, sizeof(buf), &hp, &ret) != 0) {
1514 1515
 			if(use_syslog)
1515 1516
 				syslog(LOG_WARNING, "Access Denied: Host Unknown (%s)", hostname);
1516 1517
 			return cl_error;
1517 1518
 		}
1519
+#else
1520
+		pthread_mutex_lock(&hostent_mutex);
1521
+		if((hp2 = gethostbyname(hostmail)) == NULL) {
1522
+			pthread_mutex_unlock(&hostent_mutex);
1523
+			if(use_syslog)
1524
+				syslog(LOG_WARNING, "Access Denied: Host Unknown (%s)", hostname);
1525
+			return cl_error;
1526
+		}
1527
+		memcpy(&hostent, hp2, sizeof(struct hostent));
1528
+		pthread_mutex_unlock(&hostent_mutex);
1529
+		hp = &hostent;
1530
+#endif
1518 1531
 
1519 1532
 #ifdef HAVE_INET_NTOP
1520
-		if(hp && hp->h_addr &&
1533
+		if(hp->h_addr &&
1521 1534
 		   (inet_ntop(AF_INET, (struct in_addr *)hp->h_addr, ip, sizeof(ip)) == NULL)) {
1522 1535
 			perror(hp->h_name);
1523 1536
 			/*if(use_syslog)