diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/server/getpart.c | 6 | ||||
-rw-r--r-- | tests/unit/unit1302.c | 65 |
2 files changed, 45 insertions, 26 deletions
diff --git a/tests/server/getpart.c b/tests/server/getpart.c index 743cb21b9..2351e1cc3 100644 --- a/tests/server/getpart.c +++ b/tests/server/getpart.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -166,7 +166,9 @@ static int appenddata(char **dst_buf, /* dest buffer */ if(src_b64) { /* base64 decode the given buffer */ - src_len = Curl_base64_decode(src_buf, &buf64.as_uchar); + int error = (int) Curl_base64_decode(src_buf, &buf64.as_uchar, &src_len); + if(error) + return GPE_OUT_OF_MEMORY; src_buf = buf64.as_char; if(!src_len || !src_buf) { /* diff --git a/tests/unit/unit1302.c b/tests/unit/unit1302.c index 7a61ec062..fc50c8865 100644 --- a/tests/unit/unit1302.c +++ b/tests/unit/unit1302.c @@ -45,63 +45,80 @@ UNITTEST_START char *output; unsigned char *decoded; -size_t rc; +size_t size = 0; +unsigned char anychar = 'x'; +CURLcode rc; -rc = Curl_base64_encode(data, "i", 1, &output); -fail_unless( rc == 4 , "return code should be 4" ); +rc = Curl_base64_encode(data, "i", 1, &output, &size); +fail_unless(rc == CURLE_OK, "return code should be CURLE_OK"); +fail_unless(size == 4, "size should be 4"); verify_memory( output, "aQ==", 4); Curl_safefree(output); -rc = Curl_base64_encode(data, "ii", 2, &output); -fail_unless( rc == 4 , "return code should be 4" ); +rc = Curl_base64_encode(data, "ii", 2, &output, &size); +fail_unless(rc == CURLE_OK, "return code should be CURLE_OK"); +fail_unless(size == 4, "size should be 4"); verify_memory( output, "aWk=", 4); Curl_safefree(output); -rc = Curl_base64_encode(data, "iii", 3, &output); -fail_unless( rc == 4 , "return code should be 4" ); +rc = Curl_base64_encode(data, "iii", 3, &output, &size); +fail_unless(rc == CURLE_OK, "return code should be CURLE_OK"); +fail_unless(size == 4, "size should be 4"); verify_memory( output, "aWlp", 4); Curl_safefree(output); -rc = Curl_base64_encode(data, "iiii", 4, &output); -fail_unless( rc == 8 , "return code should be 8" ); +rc = Curl_base64_encode(data, "iiii", 4, &output, &size); +fail_unless(rc == CURLE_OK, "return code should be CURLE_OK"); +fail_unless(size == 8, "size should be 8"); verify_memory( output, "aWlpaQ==", 8); Curl_safefree(output); /* 0 length makes it do strlen() */ -rc = Curl_base64_encode(data, "iiii", 0, &output); -fail_unless( rc == 8 , "return code should be 8" ); +rc = Curl_base64_encode(data, "iiii", 0, &output, &size); +fail_unless(rc == CURLE_OK, "return code should be CURLE_OK"); +fail_unless(size == 8, "size should be 8"); verify_memory( output, "aWlpaQ==", 8); Curl_safefree(output); -rc = Curl_base64_decode("aWlpaQ==", &decoded); -fail_unless(rc == 4, "return code should be 4"); +rc = Curl_base64_decode("aWlpaQ==", &decoded, &size); +fail_unless(rc == CURLE_OK, "return code should be CURLE_OK"); +fail_unless(size == 4, "size should be 4"); verify_memory(decoded, "iiii", 4); Curl_safefree(decoded); -rc = Curl_base64_decode("aWlp", &decoded); -fail_unless(rc == 3, "return code should be 3"); +rc = Curl_base64_decode("aWlp", &decoded, &size); +fail_unless(rc == CURLE_OK, "return code should be CURLE_OK"); +fail_unless(size == 3, "size should be 3"); verify_memory(decoded, "iii", 3); Curl_safefree(decoded); -rc = Curl_base64_decode("aWk=", &decoded); -fail_unless(rc == 2, "return code should be 2"); +rc = Curl_base64_decode("aWk=", &decoded, &size); +fail_unless(rc == CURLE_OK, "return code should be CURLE_OK"); +fail_unless(size == 2, "size should be 2"); verify_memory(decoded, "ii", 2); Curl_safefree(decoded); -rc = Curl_base64_decode("aQ==", &decoded); -fail_unless(rc == 1, "return code should be 1"); +rc = Curl_base64_decode("aQ==", &decoded, &size); +fail_unless(rc == CURLE_OK, "return code should be CURLE_OK"); +fail_unless(size == 1, "size should be 1"); verify_memory(decoded, "i", 2); Curl_safefree(decoded); /* this is an illegal input */ -decoded = NULL; -rc = Curl_base64_decode("aQ", &decoded); -fail_unless(rc == 0, "return code should be 0"); +size = 1; /* not zero */ +decoded = &anychar; /* not NULL */ +rc = Curl_base64_decode("aQ", &decoded, &size); +/* return code indiferent, but output shall be as follows */ +fail_unless(size == 0, "size should be 0"); fail_if(decoded, "returned pointer should be NULL"); /* this is garbage input that libcurl decodes as far as possible */ -rc = Curl_base64_decode("a\x1f==", &decoded); -fail_unless(rc == 1, "return code should be 1"); +size = 0; +decoded = NULL; +rc = Curl_base64_decode("a\x1f==", &decoded, &size); +fail_unless(rc == CURLE_OK, "return code should be CURLE_OK"); +fail_unless(size == 1, "size should be 1"); +fail_if(!decoded, "returned pointer should not be NULL"); Curl_safefree(decoded); UNITTEST_STOP |