summaryrefslogtreecommitdiff
path: root/Xtransutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'Xtransutil.c')
-rw-r--r--Xtransutil.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/Xtransutil.c b/Xtransutil.c
index a6928bb..dba1cd4 100644
--- a/Xtransutil.c
+++ b/Xtransutil.c
@@ -203,7 +203,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;
@@ -243,6 +243,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)
{
@@ -255,9 +256,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;
}
@@ -285,9 +287,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) */
@@ -337,6 +341,7 @@ TRANS(GetPeerNetworkId) (XtransConnInfo ciptr)
char *hostname;
char addrbuf[256];
const char *addr = NULL;
+ size_t len;
switch (family)
{
@@ -417,12 +422,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);
}