diff options
author | millert <> | 2022-04-13 16:20:11 +0000 |
---|---|---|
committer | millert <> | 2022-04-13 16:20:11 +0000 |
commit | 0e1b851ca91c98cb510341b07f455ae8cdca7709 (patch) | |
tree | 2c0f5e59f4c57717fc528908330f7d6eba93e4b4 | |
parent | ab2da90046213c4582bcb27db8227d1a8e9d97d3 (diff) | |
download | openbsd-0e1b851ca91c98cb510341b07f455ae8cdca7709.tar.gz openbsd-0e1b851ca91c98cb510341b07f455ae8cdca7709.tar.bz2 openbsd-0e1b851ca91c98cb510341b07f455ae8cdca7709.zip |
inet_net_pton_ipv6: avoid signed vs unsigned comparison
Use a temporary variable to store the number of bytes to be copied
(size_t) and also use it as the memcpy(3) length. Previously we
copied "size" bytes instead of just the necessary number.
OK claudio@ tb@
-rw-r--r-- | src/lib/libc/net/inet_net_pton.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/lib/libc/net/inet_net_pton.c b/src/lib/libc/net/inet_net_pton.c index aaffc1802a..610036605d 100644 --- a/src/lib/libc/net/inet_net_pton.c +++ b/src/lib/libc/net/inet_net_pton.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: inet_net_pton.c,v 1.11 2021/01/19 16:43:44 florian Exp $ */ | 1 | /* $OpenBSD: inet_net_pton.c,v 1.12 2022/04/13 16:20:11 millert Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2012 by Gilles Chehade <gilles@openbsd.org> | 4 | * Copyright (c) 2012 by Gilles Chehade <gilles@openbsd.org> |
@@ -208,6 +208,7 @@ inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) | |||
208 | struct in6_addr in6; | 208 | struct in6_addr in6; |
209 | int ret; | 209 | int ret; |
210 | int bits; | 210 | int bits; |
211 | size_t bytes | ||
211 | char buf[INET6_ADDRSTRLEN + sizeof("/128")]; | 212 | char buf[INET6_ADDRSTRLEN + sizeof("/128")]; |
212 | char *sep; | 213 | char *sep; |
213 | const char *errstr; | 214 | const char *errstr; |
@@ -235,10 +236,11 @@ inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) | |||
235 | } | 236 | } |
236 | } | 237 | } |
237 | 238 | ||
238 | if ((bits + 7) / 8 > size) { | 239 | bytes = (bits + 7) / 8; |
240 | if (bytes > size) { | ||
239 | errno = EMSGSIZE; | 241 | errno = EMSGSIZE; |
240 | return (-1); | 242 | return (-1); |
241 | } | 243 | } |
242 | memcpy(dst, &in6.s6_addr, size); | 244 | memcpy(dst, &in6.s6_addr, bytes); |
243 | return (bits); | 245 | return (bits); |
244 | } | 246 | } |