diff options
Diffstat (limited to 'lib/libc/net/base64.c')
-rw-r--r-- | lib/libc/net/base64.c | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/lib/libc/net/base64.c b/lib/libc/net/base64.c index 8a9c59e..4335030 100644 --- a/lib/libc/net/base64.c +++ b/lib/libc/net/base64.c @@ -193,10 +193,12 @@ b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) { */ int -b64_pton(const char *src, u_char *target, size_t targsize) +b64_pton(src, target, targsize) + char const *src; + u_char *target; + size_t targsize; { int tarindex, state, ch; - u_char nextbyte; char *pos; state = 0; @@ -224,28 +226,22 @@ b64_pton(const char *src, u_char *target, size_t targsize) break; case 1: if (target) { - if ((size_t)tarindex >= targsize) + if ((size_t)tarindex + 1 >= targsize) return (-1); target[tarindex] |= (pos - Base64) >> 4; - nextbyte = ((pos - Base64) & 0x0f) << 4; - if ((size_t)tarindex + 1 < targsize) - target[tarindex + 1] = nextbyte; - else if (nextbyte) - return (-1); + target[tarindex+1] = ((pos - Base64) & 0x0f) + << 4 ; } tarindex++; state = 2; break; case 2: if (target) { - if ((size_t)tarindex >= targsize) + if ((size_t)tarindex + 1 >= targsize) return (-1); target[tarindex] |= (pos - Base64) >> 2; - nextbyte = ((pos - Base64) & 0x03) << 6; - if ((size_t)tarindex + 1 < targsize) - target[tarindex + 1] = nextbyte; - else if (nextbyte) - return (-1); + target[tarindex+1] = ((pos - Base64) & 0x03) + << 6; } tarindex++; state = 3; @@ -303,8 +299,7 @@ b64_pton(const char *src, u_char *target, size_t targsize) * zeros. If we don't check them, they become a * subliminal channel. */ - if (target && (size_t)tarindex < targsize && - target[tarindex] != 0) + if (target && target[tarindex] != 0) return (-1); } } else { |