summaryrefslogtreecommitdiff
path: root/Xtrans.c
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu.herrb@laas.fr>2008-05-24 16:57:29 +0200
committerMatthieu Herrb <matthieu@bluenote.herrb.net>2008-05-24 16:57:29 +0200
commitf79638411463f81b35d984f249d0f339e28fb712 (patch)
tree99f5db42b59051777f4a88e5fabe5a7b59970f72 /Xtrans.c
parente8037cb7783adf92791e57867456cfba7b01bcd1 (diff)
OpenBSD fixes: snprintf/strlc{at,py}
Diffstat (limited to 'Xtrans.c')
-rw-r--r--Xtrans.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/Xtrans.c b/Xtrans.c
index b6b3224..ac734fa 100644
--- a/Xtrans.c
+++ b/Xtrans.c
@@ -214,13 +214,15 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
char *_protocol, *_host, *_port;
char hostnamebuf[256];
int _host_len;
+ size_t len;
PRMSG (3,"ParseAddress(%s)\n", address, 0, 0);
/* Copy the string so it can be changed */
- tmpptr = mybuf = (char *) xalloc (strlen (address) + 1);
- strcpy (mybuf, address);
+ len = strlen (address) + 1;
+ tmpptr = mybuf = (char *) xalloc (len);
+ strlcpy (mybuf, address, len);
/* Parse the string to get each component */
@@ -368,8 +370,8 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
* Now that we have all of the components, allocate new
* string space for them.
*/
-
- if ((*protocol = (char *) xalloc(strlen (_protocol) + 1)) == NULL)
+ len = strlen (_protocol) + 1;
+ if ((*protocol = (char *) xalloc(len)) == NULL)
{
/* Malloc failed */
*port = NULL;
@@ -379,9 +381,10 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
return 0;
}
else
- strcpy (*protocol, _protocol);
+ strlcpy (*protocol, _protocol, len);
- if ((*host = (char *) xalloc (strlen (_host) + 1)) == NULL)
+ len = strlen (_host) + 1;
+ if ((*host = (char *) xalloc (len)) == NULL)
{
/* Malloc failed */
*port = NULL;
@@ -392,9 +395,10 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
return 0;
}
else
- strcpy (*host, _host);
+ strlcpy (*host, _host, len);
- if ((*port = (char *) xalloc (strlen (_port) + 1)) == NULL)
+ len = strlen (_port) + 1;
+ if ((*port = (char *) xalloc (len)) == NULL)
{
/* Malloc failed */
*port = NULL;
@@ -406,7 +410,7 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
return 0;
}
else
- strcpy (*port, _port);
+ strlcpy (*port, _port, len);
xfree (tmpptr);
@@ -526,6 +530,7 @@ TRANS(Reopen) (int type, int trans_id, int fd, char *port)
Xtransport *thistrans = NULL;
char *save_port;
int i;
+ size_t len;
PRMSG (2,"Reopen(%d,%d,%s)\n", trans_id, fd, port);
@@ -545,15 +550,16 @@ TRANS(Reopen) (int type, int trans_id, int fd, char *port)
return NULL;
}
-
- if ((save_port = (char *) xalloc (strlen (port) + 1)) == NULL)
+
+ len = strlen (port) + 1;
+ if ((save_port = (char *) xalloc (len)) == NULL)
{
PRMSG (1,"Reopen: Unable to malloc port string\n", 0, 0, 0);
return NULL;
}
- strcpy (save_port, port);
+ strlcpy (save_port, port, len);
/* Get a new XtransConnInfo object */
@@ -668,18 +674,20 @@ TRANS(GetReopenInfo) (XtransConnInfo ciptr,
{
int i;
+ size_t len;
for (i = 0; i < NUMTRANS; i++)
if (Xtransports[i].transport == ciptr->transptr)
{
*trans_id = Xtransports[i].transport_id;
*fd = ciptr->fd;
-
- if ((*port = (char *) xalloc (strlen (ciptr->port) + 1)) == NULL)
+
+ len = strlen (ciptr->port) + 1;
+ if ((*port = (char *) xalloc (len)) == NULL)
return 0;
else
{
- strcpy (*port, ciptr->port);
+ strlcpy (*port, ciptr->port, len);
return 1;
}
}