diff options
author | Thierry Deval <tdeval@cvs.openbsd.org> | 2003-04-05 00:44:43 +0000 |
---|---|---|
committer | Thierry Deval <tdeval@cvs.openbsd.org> | 2003-04-05 00:44:43 +0000 |
commit | caf300eb1e575b1f5754ace36a88335b87faa2fc (patch) | |
tree | 8408142247ee498eae9efc17785b61bda530bc51 /lib | |
parent | 28816b14035bb08ad1d134a6d059b038e14eb7d8 (diff) |
sprintf -> snprintf
ok tedu@, hints deraadt@, millert@
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/net/ns_ntoa.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/libc/net/ns_ntoa.c b/lib/libc/net/ns_ntoa.c index 5ff410e28aa..35d4f28aca0 100644 --- a/lib/libc/net/ns_ntoa.c +++ b/lib/libc/net/ns_ntoa.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: ns_ntoa.c,v 1.10 2002/07/25 21:12:47 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: ns_ntoa.c,v 1.11 2003/04/05 00:44:42 tdeval Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -50,29 +50,35 @@ ns_ntoa(struct ns_addr addr) char *cp, *cp2; u_char *up = addr.x_host.c_host; u_char *uplim = up + 6; + size_t rem; net.net_e = addr.x_net; snprintf(obuf, sizeof obuf, "%x", ntohl(net.long_e)); cp = spectHex(obuf); + rem = sizeof(obuf) - (cp - obuf); cp2 = cp + 1; while (*up==0 && up < uplim) up++; if (up == uplim) { if (port) { - sprintf(cp, ".0"); + snprintf(cp, rem, ".0"); cp += 2; + rem -= 2; } } else { - sprintf(cp, ".%x", *up++); + snprintf(cp, rem, ".%x", *up++); while (up < uplim) { - while (*cp) + while (*cp) { cp++; - sprintf(cp, "%02x", *up++); + rem--; + } + snprintf(cp, rem, "%02x", *up++); } cp = spectHex(cp2); + rem = sizeof(obuf) - (cp - obuf); } if (port) { - sprintf(cp, ".%x", port); + snprintf(cp, rem, ".%x", port); spectHex(cp + 1); } return (obuf); |