[Asterisk-cvs] asterisk utils.c,1.73,1.74

markster markster
Fri Oct 21 00:15:45 CDT 2005


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv25843

Modified Files:
	utils.c 
Log Message:
Be sure to avoid octal interpretations of IP's (bug #5477)


Index: utils.c
===================================================================
RCS file: /usr/cvsroot/asterisk/utils.c,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -d -r1.73 -r1.74
--- utils.c	16 Oct 2005 03:10:33 -0000	1.73
+++ utils.c	21 Oct 2005 04:09:23 -0000	1.74
@@ -171,6 +171,7 @@
 {
 	int res;
 	int herrno;
+	int dots=0;
 	const char *s;
 	struct hostent *result = NULL;
 	/* Although it is perfectly legitimate to lookup a pure integer, for
@@ -180,12 +181,22 @@
 	s = host;
 	res = 0;
 	while(s && *s) {
-		if (!isdigit(*s))
+		if (*s == '.')
+			dots++;
+		else if (!isdigit(*s))
 			break;
 		s++;
 	}
-	if (!s || !*s)
+	if (!s || !*s) {
+		/* Forge a reply for IP's to avoid octal IP's being interpreted as octal */
+		if (dots != 3)
+			return NULL;
+		hp->hp.h_addr = hp->buf;
+		if (inet_pton(AF_INET, host, hp->hp.h_addr) > 0)
+			return &hp->hp;
 		return NULL;
+		
+	}
 #ifdef SOLARIS
 	result = gethostbyname_r(host, &hp->hp, hp->buf, sizeof(hp->buf), &herrno);
 




More information about the svn-commits mailing list