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
diff --git a/openbsc/src/gprs/gtphub.c b/openbsc/src/gprs/gtphub.c
index d7422de..a659e30 100644
--- a/openbsc/src/gprs/gtphub.c
+++ b/openbsc/src/gprs/gtphub.c
@@ -147,6 +147,9 @@
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 @@
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;
}