gtphub: fix segfault when empty config.

gsn_addr_from_str(): return error upon NULL string.
Add some debug logging.

With an empty config, no bind addresses were set, and the address parser
did not check for a NULL pointer, resulting in a segfault.

Sponsored-by: On-Waves ehi
This commit is contained in:
Neels Hofmeyr 2015-11-30 14:13:19 +01:00
parent cd865d62f0
commit 800126b1f3
1 changed files with 12 additions and 2 deletions

View File

@ -147,6 +147,9 @@ int gsn_addr_from_sockaddr(struct gsn_addr *gsna, uint16_t *port,
int gsn_addr_from_str(struct gsn_addr *gsna, const char *numeric_addr_str)
{
if ((!gsna) || (!numeric_addr_str))
return -1;
int af = AF_INET;
gsna->len = 4;
const char *pos = numeric_addr_str;
@ -857,10 +860,17 @@ static int gtphub_bind_start(struct gtphub_bind *b,
osmo_fd_cb_t cb, void *cb_data,
unsigned int ofd_id)
{
if (gsn_addr_from_str(&b->local_addr, cfg->bind.addr_str) != 0)
LOG(LOGL_DEBUG, "Starting bind %s\n", b->label);
if (gsn_addr_from_str(&b->local_addr, cfg->bind.addr_str) != 0) {
LOG(LOGL_FATAL, "Invalid bind address for %s: %s\n",
b->label, cfg->bind.addr_str);
return -1;
if (gtphub_sock_init(&b->ofd, &cfg->bind, cb, cb_data, ofd_id) != 0)
}
if (gtphub_sock_init(&b->ofd, &cfg->bind, cb, cb_data, ofd_id) != 0) {
LOG(LOGL_FATAL, "Cannot bind for %s: %s\n",
b->label, cfg->bind.addr_str);
return -1;
}
b->local_port = cfg->bind.port;
return 0;
}