diff options
author | tdeval <> | 2003-04-05 00:44:42 +0000 |
---|---|---|
committer | tdeval <> | 2003-04-05 00:44:42 +0000 |
commit | a1ab6f619cee593a4d98d863d10af25c6ecf94c4 (patch) | |
tree | ecb9bad88eaacec66b3e05e70c8d2f4644ccc6ce | |
parent | 1517aefe91cb165ee33bd66d552751a5726b06b1 (diff) | |
download | openbsd-a1ab6f619cee593a4d98d863d10af25c6ecf94c4.tar.gz openbsd-a1ab6f619cee593a4d98d863d10af25c6ecf94c4.tar.bz2 openbsd-a1ab6f619cee593a4d98d863d10af25c6ecf94c4.zip |
sprintf -> snprintf
ok tedu@, hints deraadt@, millert@
-rw-r--r-- | src/lib/libc/net/ns_ntoa.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/lib/libc/net/ns_ntoa.c b/src/lib/libc/net/ns_ntoa.c index 5ff410e28a..35d4f28aca 100644 --- a/src/lib/libc/net/ns_ntoa.c +++ b/src/lib/libc/net/ns_ntoa.c | |||
@@ -32,7 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | static char rcsid[] = "$OpenBSD: ns_ntoa.c,v 1.10 2002/07/25 21:12:47 deraadt Exp $"; | 35 | static char rcsid[] = "$OpenBSD: ns_ntoa.c,v 1.11 2003/04/05 00:44:42 tdeval Exp $"; |
36 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
37 | 37 | ||
38 | #include <sys/param.h> | 38 | #include <sys/param.h> |
@@ -50,29 +50,35 @@ ns_ntoa(struct ns_addr addr) | |||
50 | char *cp, *cp2; | 50 | char *cp, *cp2; |
51 | u_char *up = addr.x_host.c_host; | 51 | u_char *up = addr.x_host.c_host; |
52 | u_char *uplim = up + 6; | 52 | u_char *uplim = up + 6; |
53 | size_t rem; | ||
53 | 54 | ||
54 | net.net_e = addr.x_net; | 55 | net.net_e = addr.x_net; |
55 | snprintf(obuf, sizeof obuf, "%x", ntohl(net.long_e)); | 56 | snprintf(obuf, sizeof obuf, "%x", ntohl(net.long_e)); |
56 | cp = spectHex(obuf); | 57 | cp = spectHex(obuf); |
58 | rem = sizeof(obuf) - (cp - obuf); | ||
57 | cp2 = cp + 1; | 59 | cp2 = cp + 1; |
58 | while (*up==0 && up < uplim) | 60 | while (*up==0 && up < uplim) |
59 | up++; | 61 | up++; |
60 | if (up == uplim) { | 62 | if (up == uplim) { |
61 | if (port) { | 63 | if (port) { |
62 | sprintf(cp, ".0"); | 64 | snprintf(cp, rem, ".0"); |
63 | cp += 2; | 65 | cp += 2; |
66 | rem -= 2; | ||
64 | } | 67 | } |
65 | } else { | 68 | } else { |
66 | sprintf(cp, ".%x", *up++); | 69 | snprintf(cp, rem, ".%x", *up++); |
67 | while (up < uplim) { | 70 | while (up < uplim) { |
68 | while (*cp) | 71 | while (*cp) { |
69 | cp++; | 72 | cp++; |
70 | sprintf(cp, "%02x", *up++); | 73 | rem--; |
74 | } | ||
75 | snprintf(cp, rem, "%02x", *up++); | ||
71 | } | 76 | } |
72 | cp = spectHex(cp2); | 77 | cp = spectHex(cp2); |
78 | rem = sizeof(obuf) - (cp - obuf); | ||
73 | } | 79 | } |
74 | if (port) { | 80 | if (port) { |
75 | sprintf(cp, ".%x", port); | 81 | snprintf(cp, rem, ".%x", port); |
76 | spectHex(cp + 1); | 82 | spectHex(cp + 1); |
77 | } | 83 | } |
78 | return (obuf); | 84 | return (obuf); |