aboutsummaryrefslogtreecommitdiffhomepage
path: root/unix.c
diff options
context:
space:
mode:
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;
}