Skip to content

Commit f934b54

Browse files
committed
TEL-6699: Fix handling ipv6 parsing
- Minor fixes
1 parent 472a9c4 commit f934b54

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

src/mod/applications/mod_http_cache/mod_http_cache.c

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -987,17 +987,39 @@ static http_profile_t *url_cache_http_profile_find_by_fqdn(url_cache_t *cache, c
987987
}
988988

989989
switch_copy_string(host, fqdn, DOMAIN_BUF_SIZE);
990-
port = strchr(host, ':');
991-
if (port) {
992-
if (host[0] == '[') {
993-
/* IPv6 with port - find closing bracket */
994-
char *bracket = strchr(host, ']');
995-
if (bracket && bracket[1] == ':') {
996-
memmove(host, host + 1, bracket - host);
997-
host[bracket - host - 1] = '\0';
998-
}
990+
991+
/* Handle IPv6 addresses with brackets */
992+
if (host[0] == '[') {
993+
char *bracket_close = strchr(host, ']');
994+
if (!bracket_close) {
995+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
996+
"Malformed IPv6 address in URL '%s': opening bracket '[' without closing bracket ']'\n", fqdn);
997+
return NULL;
998+
}
999+
1000+
if (bracket_close[1] == ':') {
1001+
memmove(host, host + 1, bracket_close - host - 1);
1002+
host[bracket_close - host - 1] = '\0';
1003+
} else if (bracket_close[1] == '\0') {
1004+
memmove(host, host + 1, bracket_close - host - 1);
1005+
host[bracket_close - host - 1] = '\0';
9991006
} else {
1000-
/* IPv4 with port, or IPv6 without brackets */
1007+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
1008+
"Malformed IPv6 address in URL '%s': invalid character '%c' after closing bracket ']'\n",
1009+
fqdn, bracket_close[1]);
1010+
return NULL;
1011+
}
1012+
} else {
1013+
/* IPv4 with port, or IPv6 without brackets */
1014+
char *bracket_close = strchr(host, ']');
1015+
if (bracket_close) {
1016+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
1017+
"Malformed IPv6 address in URL '%s': closing bracket ']' without opening bracket '['\n", fqdn);
1018+
return NULL;
1019+
}
1020+
1021+
port = strchr(host, ':');
1022+
if (port) {
10011023
int colon_count = 0;
10021024
char *p;
10031025
for (p = host; *p; p++) {

src/mod/formats/mod_shout/mod_shout.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,7 +1749,6 @@ static switch_status_t load_config(switch_memory_pool_t* pool)
17491749

17501750
/* Create default profile from global settings */
17511751
globals.default_profile = switch_core_alloc(globals.pool, sizeof(shout_profile_t));
1752-
memset(globals.default_profile, 0, sizeof(shout_profile_t));
17531752
switch_set_string(globals.default_profile->name, "default");
17541753
switch_set_string(globals.default_profile->decoder, globals.decoder);
17551754
globals.default_profile->bind_ip = globals.bind_ip;
@@ -1773,7 +1772,6 @@ static switch_status_t load_config(switch_memory_pool_t* pool)
17731772
}
17741773

17751774
profile = switch_core_alloc(globals.pool, sizeof(shout_profile_t));
1776-
memset(profile, 0, sizeof(shout_profile_t));
17771775
switch_set_string(profile->name, profile_name);
17781776

17791777
/* Copy default values from global settings */

0 commit comments

Comments
 (0)