From fc58f6b82057f4db3e5bec9fe0bfe8afbec23c94 Mon Sep 17 00:00:00 2001 From: Hannes Gredler Date: Fri, 21 Feb 2014 09:27:35 +0100 Subject: [PATCH] fix crash: Create a local copy of the string. --- lib/ebus-bus.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/ebus-bus.c b/lib/ebus-bus.c index e87cc41c..c73d4917 100644 --- a/lib/ebus-bus.c +++ b/lib/ebus-bus.c @@ -557,10 +557,16 @@ eb_bus_open(const char *dev, int *fd) if (devicetype == BUS_DEVICE_SOCKET) { struct sockaddr_in sock; + char *hostport; memset((char *) &sock, 0, sizeof(sock)); - - char *host = strtok((char *) dev, ":"); + + /* + * Create a local copy of the string + * before the strtok() calls change it. + */ + hostport = strdup(dev); + char *host = strtok(hostport, ":"); char *port = strtok(NULL, ":"); if (inet_addr(host) == INADDR_NONE) { @@ -585,6 +591,7 @@ eb_bus_open(const char *dev, int *fd) err_ret_if(ret < 0, -1); *fd = bfd; + free(hostport); } return 0;