summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWayne Davison <wayned@samba.org>2006-10-16 18:11:24 +0000
committerWayne Davison <wayned@samba.org>2006-10-16 18:11:24 +0000
commitf210dcadf4a921f8ca3718c0b972cee153793488 (patch)
treecb3a35299a44ce9d88b8182c3973619fa4518504 /lib
parent178a1d20483eae24dd15ff5c54257194a4d7afde (diff)
downloadrsync-f210dcadf4a921f8ca3718c0b972cee153793488.tar.gz
rsync-f210dcadf4a921f8ca3718c0b972cee153793488.tar.bz2
rsync-f210dcadf4a921f8ca3718c0b972cee153793488.zip
- Fixed a compile problem ("len" not defined) in inet_ntop4().
- Replaced sprintf() with snprintf() in inet_ntop6().
Diffstat (limited to 'lib')
-rw-r--r--lib/inet_ntop.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/inet_ntop.c b/lib/inet_ntop.c
index 15e3ebd3..7be7368e 100644
--- a/lib/inet_ntop.c
+++ b/lib/inet_ntop.c
@@ -75,9 +75,10 @@ inet_ntop4(const unsigned char *src, char *dst, size_t size)
{
static const char *fmt = "%u.%u.%u.%u";
char tmp[sizeof "255.255.255.255"];
+ size_t len;
- if ((size_t)sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) >= size)
- {
+ len = snprintf(tmp, sizeof tmp, fmt, src[0], src[1], src[2], src[3]);
+ if (len >= size) {
errno = ENOSPC;
return (NULL);
}
@@ -106,7 +107,7 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size)
char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
struct { int base, len; } best, cur;
unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ];
- int i;
+ int i, inc;
/*
* Preprocess:
@@ -157,13 +158,14 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size)
/* Is this address an encapsulated IPv4? */
if (i == 6 && best.base == 0 &&
(best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
- if (!inet_ntop4(src+12, tp,
- sizeof tmp - (tp - tmp)))
+ if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
return (NULL);
tp += strlen(tp);
break;
}
- tp += sprintf(tp, "%x", words[i]);
+ inc = snprintf(tp, 5, "%x", words[i]);
+ assert(inc < 5);
+ tp += inc;
}
/* Was it a trailing run of 0x00's? */
if (best.base != -1 && (best.base + best.len) ==