diff options
Diffstat (limited to 'src/microhttpd/base64.c')
-rw-r--r-- | src/microhttpd/base64.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/microhttpd/base64.c b/src/microhttpd/base64.c index 1f07cd7e..3d2dd3f1 100644 --- a/src/microhttpd/base64.c +++ b/src/microhttpd/base64.c | |||
@@ -37,9 +37,10 @@ static const char base64_digits[] = | |||
37 | 37 | ||
38 | 38 | ||
39 | char * | 39 | char * |
40 | BASE64Decode (const char *src) | 40 | BASE64Decode (const char *src, |
41 | size_t in_len, | ||
42 | size_t *out_len) | ||
41 | { | 43 | { |
42 | size_t in_len = strlen (src); | ||
43 | unsigned char *dest; | 44 | unsigned char *dest; |
44 | char *result; | 45 | char *result; |
45 | 46 | ||
@@ -52,7 +53,7 @@ BASE64Decode (const char *src) | |||
52 | result = (char *) dest; | 53 | result = (char *) dest; |
53 | if (NULL == result) | 54 | if (NULL == result) |
54 | return NULL; /* out of memory */ | 55 | return NULL; /* out of memory */ |
55 | while (*src) | 56 | for (; 0 < in_len && 0 != *src; in_len -= 4) |
56 | { | 57 | { |
57 | char a = base64_digits[(unsigned char) *(src++)]; | 58 | char a = base64_digits[(unsigned char) *(src++)]; |
58 | char b = base64_digits[(unsigned char) *(src++)]; | 59 | char b = base64_digits[(unsigned char) *(src++)]; |
@@ -75,6 +76,8 @@ BASE64Decode (const char *src) | |||
75 | | ((unsigned char) d); | 76 | | ((unsigned char) d); |
76 | } | 77 | } |
77 | *dest = 0; | 78 | *dest = 0; |
79 | if (NULL != out_len) | ||
80 | *out_len = (size_t) (dest - (unsigned char *) result); | ||
78 | return result; | 81 | return result; |
79 | } | 82 | } |
80 | 83 | ||