]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
base64: Remove unnecessary overflow checks.
authorAndre Noll <maan@tuebingen.mpg.de>
Tue, 28 Apr 2015 16:17:42 +0000 (18:17 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Tue, 23 Aug 2016 14:50:42 +0000 (16:50 +0200)
Since we decode no more than encoded_size many bytes, and the output
buffer is allocated large enough to store the decoded data, we won't
ever overflow the output buffer. This commit removes the pointless
checks.

base64.c

index 4809a2f285f63dd83132f693be23f68945fce21d..382f1519370d77cd33f473023f493571caf0a53a 100644 (file)
--- a/base64.c
+++ b/base64.c
@@ -46,12 +46,10 @@ int base64_decode(char const *src, size_t encoded_size, char **result,
        char *pos;
        const char *end = src + encoded_size;
        unsigned char *target;
-       size_t targsize;
 
        if (encoded_size == (size_t)-1)
                encoded_size = strlen(src);
-       targsize = BASE64_MAX_DECODED_SIZE(encoded_size);
-       target = para_malloc(targsize + 1);
+       target = para_malloc(BASE64_MAX_DECODED_SIZE(encoded_size) + 1);
 
        state = 0;
        tarindex = 0;
@@ -70,30 +68,22 @@ int base64_decode(char const *src, size_t encoded_size, char **result,
 
                switch (state) {
                case 0:
-                       if (tarindex >= targsize)
-                               goto fail;
                        target[tarindex] = (pos - Base64) << 2;
                        state = 1;
                        break;
                case 1:
-                       if (tarindex + 1 >= targsize)
-                               goto fail;
                        target[tarindex] |= (pos - Base64) >> 4;
                        target[tarindex + 1] = ((pos - Base64) & 0x0f) << 4;
                        tarindex++;
                        state = 2;
                        break;
                case 2:
-                       if (tarindex + 1 >= targsize)
-                               goto fail;
                        target[tarindex] |= (pos - Base64) >> 2;
                        target[tarindex + 1] = ((pos - Base64) & 0x03) << 6;
                        tarindex++;
                        state = 3;
                        break;
                case 3:
-                       if (tarindex >= targsize)
-                               goto fail;
                        target[tarindex] |= pos - Base64;
                        tarindex++;
                        state = 0;