mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-10-31 18:55:19 +00:00 
			
		
		
		
	Be sure to avoid octal interpretations of IP's (bug #5477)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6838 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
		
							
								
								
									
										15
									
								
								utils.c
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								utils.c
									
									
									
									
									
								
							| @@ -171,6 +171,7 @@ struct hostent *ast_gethostbyname(const char *host, struct ast_hostent *hp) | |||||||
| { | { | ||||||
| 	int res; | 	int res; | ||||||
| 	int herrno; | 	int herrno; | ||||||
|  | 	int dots=0; | ||||||
| 	const char *s; | 	const char *s; | ||||||
| 	struct hostent *result = NULL; | 	struct hostent *result = NULL; | ||||||
| 	/* Although it is perfectly legitimate to lookup a pure integer, for | 	/* Although it is perfectly legitimate to lookup a pure integer, for | ||||||
| @@ -180,12 +181,22 @@ struct hostent *ast_gethostbyname(const char *host, struct ast_hostent *hp) | |||||||
| 	s = host; | 	s = host; | ||||||
| 	res = 0; | 	res = 0; | ||||||
| 	while(s && *s) { | 	while(s && *s) { | ||||||
| 		if (!isdigit(*s)) | 		if (*s == '.') | ||||||
|  | 			dots++; | ||||||
|  | 		else if (!isdigit(*s)) | ||||||
| 			break; | 			break; | ||||||
| 		s++; | 		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; | 			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 | #ifdef SOLARIS | ||||||
| 	result = gethostbyname_r(host, &hp->hp, hp->buf, sizeof(hp->buf), &herrno); | 	result = gethostbyname_r(host, &hp->hp, hp->buf, sizeof(hp->buf), &herrno); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user