aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/libmsc
diff options
context:
space:
mode:
Diffstat (limited to 'openbsc/src/libmsc')
-rw-r--r--openbsc/src/libmsc/smpp_smsc.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/openbsc/src/libmsc/smpp_smsc.c b/openbsc/src/libmsc/smpp_smsc.c
index 83c29f69e..e4acd3ab7 100644
--- a/openbsc/src/libmsc/smpp_smsc.c
+++ b/openbsc/src/libmsc/smpp_smsc.c
@@ -972,14 +972,19 @@ struct smsc *smpp_smsc_alloc_init(void *ctx)
/*! \brief Set the SMPP address and port without binding. */
int smpp_smsc_conf(struct smsc *smsc, const char *bind_addr, uint16_t port)
{
+ smsc->listen_port = port;
+
+ /* Avoid use-after-free if bind_addr == smsc->bind_addr */
+ if (smsc->bind_addr == bind_addr)
+ return 0;
+
talloc_free((void*)smsc->bind_addr);
smsc->bind_addr = NULL;
if (bind_addr) {
- smsc->bind_addr = talloc_strdup(smsc, bind_addr);
+ smsc->bind_addr = bind_addr ? talloc_strdup(smsc, bind_addr) : NULL;
if (!smsc->bind_addr)
return -ENOMEM;
}
- smsc->listen_port = port;
return 0;
}