diff options
Diffstat (limited to 'Xtransutil.c')
-rw-r--r-- | Xtransutil.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/Xtransutil.c b/Xtransutil.c index 884cfdf..c83e029 100644 --- a/Xtransutil.c +++ b/Xtransutil.c @@ -196,7 +196,7 @@ TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr **addrp) if (!*addrp) *addrp = malloc (len + 1); if (*addrp) { - strcpy ((char *) *addrp, hostnamebuf); + strlcpy ((char *) *addrp, hostnamebuf, len + 1); *addrlenp = len; } else { *addrlenp = 0; @@ -236,6 +236,7 @@ TRANS(GetMyNetworkId) (XtransConnInfo ciptr) char hostnamebuf[256]; char *networkId = NULL; const char *transName = ciptr->transptr->TransName; + size_t len; if (gethostname (hostnamebuf, sizeof (hostnamebuf)) < 0) { @@ -248,9 +249,10 @@ TRANS(GetMyNetworkId) (XtransConnInfo ciptr) case AF_UNIX: { struct sockaddr_un *saddr = (struct sockaddr_un *) addr; - networkId = malloc (3 + strlen (transName) + - strlen (hostnamebuf) + strlen (saddr->sun_path)); - sprintf (networkId, "%s/%s:%s", transName, + len = 3 + strlen (transName) + + strlen (hostnamebuf) + strlen (saddr->sun_path); + networkId = malloc (len); + snprintf (networkId, len, "%s/%s:%s", transName, hostnamebuf, saddr->sun_path); break; } @@ -278,9 +280,11 @@ TRANS(GetMyNetworkId) (XtransConnInfo ciptr) portnum = ntohs (saddr->sin_port); snprintf (portnumbuf, sizeof(portnumbuf), "%d", portnum); - networkId = malloc (3 + strlen (transName) + - strlen (hostnamebuf) + strlen (portnumbuf)); - sprintf (networkId, "%s/%s:%s", transName, hostnamebuf, portnumbuf); + len = 3 + strlen (transName) + + strlen (hostnamebuf) + strlen (portnumbuf); + networkId = malloc (len); + snprintf (networkId, len, "%s/%s:%s", transName, hostnamebuf, + portnumbuf); break; } #endif /* defined(TCPCONN) */ @@ -318,6 +322,7 @@ TRANS(GetPeerNetworkId) (XtransConnInfo ciptr) char *hostname; char addrbuf[256]; const char *addr = NULL; + size_t len; switch (family) { @@ -398,12 +403,13 @@ TRANS(GetPeerNetworkId) (XtransConnInfo ciptr) return (NULL); } + len = strlen (ciptr->transptr->TransName) + strlen (addr) + 2; + hostname = malloc (len); + strlcpy (hostname, ciptr->transptr->TransName, len); + strlcat (hostname, "/", len); - hostname = malloc (strlen (ciptr->transptr->TransName) + strlen (addr) + 2); - strcpy (hostname, ciptr->transptr->TransName); - strcat (hostname, "/"); if (addr) - strcat (hostname, addr); + strlcat (hostname, addr, len); return (hostname); } |