summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormillert <>2014-02-05 14:20:43 +0000
committermillert <>2014-02-05 14:20:43 +0000
commit6d230d5ca25a8820f1ad99b92d9152a6a606a042 (patch)
tree7c69176afc3cbe84b8e38d89fd35eebfb2389a12
parent0f55e154755690e3b4b8fcc64d557f9a9416b9c8 (diff)
downloadopenbsd-6d230d5ca25a8820f1ad99b92d9152a6a606a042.tar.gz
openbsd-6d230d5ca25a8820f1ad99b92d9152a6a606a042.tar.bz2
openbsd-6d230d5ca25a8820f1ad99b92d9152a6a606a042.zip
Always set errno when returning NULL. OK kettenis@ henning@
-rw-r--r--src/lib/libc/net/inet_ntop.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/lib/libc/net/inet_ntop.c b/src/lib/libc/net/inet_ntop.c
index 9deb352e24..359acd8cda 100644
--- a/src/lib/libc/net/inet_ntop.c
+++ b/src/lib/libc/net/inet_ntop.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: inet_ntop.c,v 1.8 2008/12/09 19:38:38 otto Exp $ */ 1/* $OpenBSD: inet_ntop.c,v 1.9 2014/02/05 14:20:43 millert Exp $ */
2 2
3/* Copyright (c) 1996 by Internet Software Consortium. 3/* Copyright (c) 1996 by Internet Software Consortium.
4 * 4 *
@@ -34,7 +34,7 @@
34static const char *inet_ntop4(const u_char *src, char *dst, size_t size); 34static const char *inet_ntop4(const u_char *src, char *dst, size_t size);
35static const char *inet_ntop6(const u_char *src, char *dst, size_t size); 35static const char *inet_ntop6(const u_char *src, char *dst, size_t size);
36 36
37/* char * 37/* const char *
38 * inet_ntop(af, src, dst, size) 38 * inet_ntop(af, src, dst, size)
39 * convert a network format address to presentation format. 39 * convert a network format address to presentation format.
40 * return: 40 * return:
@@ -148,16 +148,20 @@ inet_ntop6(const u_char *src, char *dst, size_t size)
148 if (best.base != -1 && i >= best.base && 148 if (best.base != -1 && i >= best.base &&
149 i < (best.base + best.len)) { 149 i < (best.base + best.len)) {
150 if (i == best.base) { 150 if (i == best.base) {
151 if (tp + 1 >= ep) 151 if (tp + 1 >= ep) {
152 errno = ENOSPC;
152 return (NULL); 153 return (NULL);
154 }
153 *tp++ = ':'; 155 *tp++ = ':';
154 } 156 }
155 continue; 157 continue;
156 } 158 }
157 /* Are we following an initial run of 0x00s or any real hex? */ 159 /* Are we following an initial run of 0x00s or any real hex? */
158 if (i != 0) { 160 if (i != 0) {
159 if (tp + 1 >= ep) 161 if (tp + 1 >= ep) {
162 errno = ENOSPC;
160 return (NULL); 163 return (NULL);
164 }
161 *tp++ = ':'; 165 *tp++ = ':';
162 } 166 }
163 /* Is this address an encapsulated IPv4? */ 167 /* Is this address an encapsulated IPv4? */
@@ -169,18 +173,24 @@ inet_ntop6(const u_char *src, char *dst, size_t size)
169 break; 173 break;
170 } 174 }
171 advance = snprintf(tp, ep - tp, "%x", words[i]); 175 advance = snprintf(tp, ep - tp, "%x", words[i]);
172 if (advance <= 0 || advance >= ep - tp) 176 if (advance <= 0 || advance >= ep - tp) {
177 errno = ENOSPC;
173 return (NULL); 178 return (NULL);
179 }
174 tp += advance; 180 tp += advance;
175 } 181 }
176 /* Was it a trailing run of 0x00's? */ 182 /* Was it a trailing run of 0x00's? */
177 if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) { 183 if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) {
178 if (tp + 1 >= ep) 184 if (tp + 1 >= ep) {
185 errno = ENOSPC;
179 return (NULL); 186 return (NULL);
187 }
180 *tp++ = ':'; 188 *tp++ = ':';
181 } 189 }
182 if (tp + 1 >= ep) 190 if (tp + 1 >= ep) {
191 errno = ENOSPC;
183 return (NULL); 192 return (NULL);
193 }
184 *tp++ = '\0'; 194 *tp++ = '\0';
185 195
186 /* 196 /*