diff options
author | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2015-11-30 14:13:19 +0100 |
---|---|---|
committer | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2015-12-03 11:44:08 +0100 |
commit | 800126b1f33986ca9ffc6f2a65c91264a969d078 (patch) | |
tree | c0e335682e717099b3fa5a89ba1df777bf41f2d6 /openbsc/src/gprs/gtphub.c | |
parent | cd865d62f0446135258189184664a146b28db975 (diff) |
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
Diffstat (limited to 'openbsc/src/gprs/gtphub.c')
-rw-r--r-- | openbsc/src/gprs/gtphub.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/openbsc/src/gprs/gtphub.c b/openbsc/src/gprs/gtphub.c index d7422de0f..a659e30af 100644 --- a/openbsc/src/gprs/gtphub.c +++ b/openbsc/src/gprs/gtphub.c @@ -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; } |