diff options
author | tedu <> | 2013-12-31 02:32:56 +0000 |
---|---|---|
committer | tedu <> | 2013-12-31 02:32:56 +0000 |
commit | eb4db0ab616f0dfed0cc0ed08be18d66e257f583 (patch) | |
tree | 73762b3e48ee72aa6966cbc8631cdef601cf220e /src/lib | |
parent | 382438d17af9b7ccce3e4d3890cc9b1785f14d71 (diff) | |
download | openbsd-eb4db0ab616f0dfed0cc0ed08be18d66e257f583.tar.gz openbsd-eb4db0ab616f0dfed0cc0ed08be18d66e257f583.tar.bz2 openbsd-eb4db0ab616f0dfed0cc0ed08be18d66e257f583.zip |
don't try writing past the end unless we have to
ok gilles millert
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libc/net/base64.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/lib/libc/net/base64.c b/src/lib/libc/net/base64.c index 78ef449a75..7c3d1d319f 100644 --- a/src/lib/libc/net/base64.c +++ b/src/lib/libc/net/base64.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: base64.c,v 1.6 2013/11/24 23:51:28 deraadt Exp $ */ | 1 | /* $OpenBSD: base64.c,v 1.7 2013/12/31 02:32:56 tedu Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 1996 by Internet Software Consortium. | 4 | * Copyright (c) 1996 by Internet Software Consortium. |
@@ -194,6 +194,7 @@ b64_pton(src, target, targsize) | |||
194 | size_t targsize; | 194 | size_t targsize; |
195 | { | 195 | { |
196 | int tarindex, state, ch; | 196 | int tarindex, state, ch; |
197 | u_char nextbyte; | ||
197 | char *pos; | 198 | char *pos; |
198 | 199 | ||
199 | state = 0; | 200 | state = 0; |
@@ -221,22 +222,28 @@ b64_pton(src, target, targsize) | |||
221 | break; | 222 | break; |
222 | case 1: | 223 | case 1: |
223 | if (target) { | 224 | if (target) { |
224 | if (tarindex + 1 >= targsize) | 225 | if (tarindex >= targsize) |
225 | return (-1); | 226 | return (-1); |
226 | target[tarindex] |= (pos - Base64) >> 4; | 227 | target[tarindex] |= (pos - Base64) >> 4; |
227 | target[tarindex+1] = ((pos - Base64) & 0x0f) | 228 | nextbyte = ((pos - Base64) & 0x0f) << 4; |
228 | << 4 ; | 229 | if (tarindex + 1 < targsize) |
230 | target[tarindex+1] = nextbyte; | ||
231 | else if (nextbyte) | ||
232 | return (-1); | ||
229 | } | 233 | } |
230 | tarindex++; | 234 | tarindex++; |
231 | state = 2; | 235 | state = 2; |
232 | break; | 236 | break; |
233 | case 2: | 237 | case 2: |
234 | if (target) { | 238 | if (target) { |
235 | if (tarindex + 1 >= targsize) | 239 | if (tarindex >= targsize) |
236 | return (-1); | 240 | return (-1); |
237 | target[tarindex] |= (pos - Base64) >> 2; | 241 | target[tarindex] |= (pos - Base64) >> 2; |
238 | target[tarindex+1] = ((pos - Base64) & 0x03) | 242 | nextbyte = ((pos - Base64) & 0x03) << 6; |
239 | << 6; | 243 | if (tarindex + 1 < targsize) |
244 | target[tarindex+1] = nextbyte; | ||
245 | else if (nextbyte) | ||
246 | return (-1); | ||
240 | } | 247 | } |
241 | tarindex++; | 248 | tarindex++; |
242 | state = 3; | 249 | state = 3; |
@@ -292,7 +299,8 @@ b64_pton(src, target, targsize) | |||
292 | * zeros. If we don't check them, they become a | 299 | * zeros. If we don't check them, they become a |
293 | * subliminal channel. | 300 | * subliminal channel. |
294 | */ | 301 | */ |
295 | if (target && target[tarindex] != 0) | 302 | if (target && tarindex < targsize && |
303 | target[tarindex] != 0) | ||
296 | return (-1); | 304 | return (-1); |
297 | } | 305 | } |
298 | } else { | 306 | } else { |