Merged revisions 323392,323394 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8 ........ r323392 | rmudgett | 2011-06-14 12:21:24 -0500 (Tue, 14 Jun 2011) | 6 lines Add more strict hostname checking to ast_dnsmgr_lookup(). Change suggested in review. Review: https://reviewboard.asterisk.org/r/1240/ ........ r323394 | rmudgett | 2011-06-14 12:21:39 -0500 (Tue, 14 Jun 2011) | 2 lines Made ast_sockaddr_split_hostport() port warning msgs more meaningful. ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@323397 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
parent
bdb71463e7
commit
97ebcb0ffb
|
@ -135,7 +135,7 @@ int ast_dnsmgr_lookup(const char *name, struct ast_sockaddr *result, struct ast_
|
||||||
* If it's actually an IP address and not a name, there's no
|
* If it's actually an IP address and not a name, there's no
|
||||||
* need for a managed lookup.
|
* need for a managed lookup.
|
||||||
*/
|
*/
|
||||||
if (ast_sockaddr_parse(result, name, 0)) {
|
if (ast_sockaddr_parse(result, name, PARSE_PORT_FORBID)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,8 +121,10 @@ char *ast_sockaddr_stringify_fmt(const struct ast_sockaddr *sa, int format)
|
||||||
int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
|
int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
|
||||||
{
|
{
|
||||||
char *s = str;
|
char *s = str;
|
||||||
|
char *orig_str = str;/* Original string in case the port presence is incorrect. */
|
||||||
|
char *host_end = NULL;/* Delay terminating the host in case the port presence is incorrect. */
|
||||||
|
|
||||||
ast_debug(5, "Splitting '%s' gives...\n", str);
|
ast_debug(5, "Splitting '%s' into...\n", str);
|
||||||
*host = NULL;
|
*host = NULL;
|
||||||
*port = NULL;
|
*port = NULL;
|
||||||
if (*s == '[') {
|
if (*s == '[') {
|
||||||
|
@ -130,7 +132,8 @@ int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
|
||||||
for (; *s && *s != ']'; ++s) {
|
for (; *s && *s != ']'; ++s) {
|
||||||
}
|
}
|
||||||
if (*s == ']') {
|
if (*s == ']') {
|
||||||
*s++ = '\0';
|
host_end = s;
|
||||||
|
++s;
|
||||||
}
|
}
|
||||||
if (*s == ':') {
|
if (*s == ':') {
|
||||||
*port = s + 1;
|
*port = s + 1;
|
||||||
|
@ -148,11 +151,10 @@ int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*port) {
|
if (*port) {
|
||||||
**port = '\0';
|
host_end = *port;
|
||||||
++*port;
|
++*port;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast_debug(5, "...host '%s' and port '%s'.\n", *host, *port);
|
|
||||||
|
|
||||||
switch (flags & PARSE_PORT_MASK) {
|
switch (flags & PARSE_PORT_MASK) {
|
||||||
case PARSE_PORT_IGNORE:
|
case PARSE_PORT_IGNORE:
|
||||||
|
@ -160,18 +162,23 @@ int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
|
||||||
break;
|
break;
|
||||||
case PARSE_PORT_REQUIRE:
|
case PARSE_PORT_REQUIRE:
|
||||||
if (*port == NULL) {
|
if (*port == NULL) {
|
||||||
ast_log(LOG_WARNING, "missing port\n");
|
ast_log(LOG_WARNING, "Port missing in %s\n", orig_str);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PARSE_PORT_FORBID:
|
case PARSE_PORT_FORBID:
|
||||||
if (*port != NULL) {
|
if (*port != NULL) {
|
||||||
ast_log(LOG_WARNING, "port disallowed\n");
|
ast_log(LOG_WARNING, "Port disallowed in %s\n", orig_str);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Can terminate the host string now if needed. */
|
||||||
|
if (host_end) {
|
||||||
|
*host_end = '\0';
|
||||||
|
}
|
||||||
|
ast_debug(5, "...host '%s' and port '%s'.\n", *host, *port ? *port : "");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue