Browse code

Call res_close and fix blacklist mutex

git-svn: trunk@2114

Nigel Horne authored on 2006/07/24 04:14:40
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Sun Jul 23 20:13:46 BST 2006 (njh)
2
+----------------------------------
3
+  * clamav-milter:	Call res_close() and fix blacklist mutex
4
+
1 5
 Sun Jul 23 16:47:58 BST 2006 (njh)
2 6
 ---------------------------------
3 7
   * clamav-milter:	Report phishing code now fully enabled, added
... ...
@@ -23,7 +23,7 @@
23 23
  *
24 24
  * For installation instructions see the file INSTALL that came with this file
25 25
  */
26
-static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.269 2006/07/23 15:49:24 njh Exp $";
26
+static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.270 2006/07/23 19:13:10 njh Exp $";
27 27
 
28 28
 #define	CM_VERSION	"devel-230706"
29 29
 
... ...
@@ -5500,7 +5500,7 @@ isBlacklisted(const char *ip_address)
5500 5500
 		return 1;
5501 5501
 
5502 5502
 	/* timedout: remove the IP from the blacklist */
5503
-	pthread_mutex_unlock(&blacklist_mutex);
5503
+	pthread_mutex_lock(&blacklist_mutex);
5504 5504
 	tableRemove(blacklist, ip_address);
5505 5505
 	pthread_mutex_unlock(&blacklist_mutex);
5506 5506
 
... ...
@@ -5525,7 +5525,7 @@ mx(void)
5525 5525
 		u_char u[PACKETSZ];
5526 5526
 	} q;
5527 5527
 	const HEADER *hp;
5528
-	int len, i;
5528
+	int len, i, was_initialised;
5529 5529
 
5530 5530
 	if(gethostname(name, sizeof(name)) < 0) {
5531 5531
 		perror("gethostname");
... ...
@@ -5539,23 +5539,34 @@ mx(void)
5539 5539
 			return;
5540 5540
 	}
5541 5541
 
5542
-	if(res_init() < 0)
5542
+	was_initialised = _res.options & RES_INIT;
5543
+
5544
+	if((!was_initialised) && res_init() < 0)
5543 5545
 		return;
5544 5546
 
5545 5547
 	len = res_query(name, C_IN, T_MX, (u_char *)&q, sizeof(q));
5546
-	if(len < 0)
5548
+	if(len < 0) {
5549
+		if(!was_initialised)
5550
+			res_close();
5547 5551
 		return;	/* Host has no MX records */
5552
+	}
5548 5553
 
5549
-	if((unsigned int)len > sizeof(q))
5554
+	if((unsigned int)len > sizeof(q)) {
5555
+		if(!was_initialised)
5556
+			res_close();
5550 5557
 		return;
5558
+	}
5551 5559
 
5552 5560
 	hp = &(q.h);
5553 5561
 	p = q.u + HFIXEDSZ;
5554 5562
 	end = q.u + len;
5555 5563
 
5556 5564
 	for(i = ntohs(hp->qdcount); i--; p += len + QFIXEDSZ)
5557
-		if((len = dn_skipname(p, end)) < 0)
5565
+		if((len = dn_skipname(p, end)) < 0) {
5566
+			if(!was_initialised)
5567
+				res_close();
5558 5568
 			return;
5569
+		}
5559 5570
 
5560 5571
 	i = ntohs(hp->ancount);
5561 5572
 
... ...
@@ -5591,6 +5602,8 @@ mx(void)
5591 5591
 		} else
5592 5592
 			resolve(buf);
5593 5593
 	}
5594
+	if(!was_initialised)
5595
+		res_close();
5594 5596
 }
5595 5597
 
5596 5598
 /*