diff options
author | Damien Miller <djm@mindrot.org> | 2001-09-25 22:21:52 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2001-09-25 22:21:52 +1000 |
commit | 5f4b10088fdb88ad4326211ebe9933b92d4f7eb7 (patch) | |
tree | d3a3c3b83ca95530a1445ad850a5c8fdd4b9ae51 /openbsd-compat/inet_ntop.c | |
parent | e8bb450af9bb67f9b8b2c7a1fc5659935a286788 (diff) |
- (djm) Avoid bad and unportable sprintf usage in compat code
Diffstat (limited to 'openbsd-compat/inet_ntop.c')
-rw-r--r-- | openbsd-compat/inet_ntop.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/openbsd-compat/inet_ntop.c b/openbsd-compat/inet_ntop.c index bf3d97ad..2b8d31f8 100644 --- a/openbsd-compat/inet_ntop.c +++ b/openbsd-compat/inet_ntop.c @@ -104,7 +104,8 @@ inet_ntop4(src, dst, size) static const char fmt[] = "%u.%u.%u.%u"; char tmp[sizeof "255.255.255.255"]; - if (sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) > size) { + if (snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], + src[3]) > size) { errno = ENOSPC; return (NULL); } @@ -190,7 +191,8 @@ inet_ntop6(src, dst, size) tp += strlen(tp); break; } - tp += sprintf(tp, "%x", words[i]); + snprintf(tp, sizeof(tmp - (tp - tmp)), "%x", words[i]); + tp += strlen(tp); } /* Was it a trailing run of 0x00's? */ if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) |