aboutsummaryrefslogtreecommitdiffhomepage
path: root/unix.c
diff options
context:
space:
mode:
authorLee Salzman <[email protected]>2014-03-08 18:46:39 +0200
committerLee Salzman <[email protected]>2014-03-08 18:46:39 +0200
commit73c930881f7acabc9bea99eb698d0824cbe22c3e (patch)
treeedd210e87e2a4eab7bd7ae2112c72732e6b04519 /unix.c
parent5721b667f2d57d1c8b65ef5575379f6756ec2938 (diff)
downloadenet-73c930881f7acabc9bea99eb698d0824cbe22c3e.tar.gz
enet-73c930881f7acabc9bea99eb698d0824cbe22c3e.zip
avoid some strncpy usage
Diffstat (limited to 'unix.c')
-rw-r--r--unix.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/unix.c b/unix.c
index e9a0602..5e7c731 100644
--- a/unix.c
+++ b/unix.c
@@ -138,7 +138,12 @@ enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameL
#else
char * addr = inet_ntoa (* (struct in_addr *) & address -> host);
if (addr != NULL)
- strncpy (name, addr, nameLength);
+ {
+ size_t addrLen = strlen(addr);
+ if (addrLen >= nameLength)
+ return -1;
+ memcpy (name, addr, addrLen + 1);
+ }
else
#endif
return -1;
@@ -170,8 +175,13 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng
if (hostEntry == NULL)
return enet_address_get_host_ip (address, name, nameLength);
-
- strncpy (name, hostEntry -> h_name, nameLength);
+ else
+ {
+ size_t hostLen = strlen (hostEntry -> h_name);
+ if (hostLen >= nameLength)
+ return -1;
+ memcpy (name, hostEntry -> h_name, hostLen + 1);
+ }
return 0;
}