From c92c30edbde3b7f7562c2bcb4a06626781c55f1d Mon Sep 17 00:00:00 2001 From: Steve Holme Date: Sun, 1 Dec 2013 11:05:11 +0000 Subject: base64: Extended validation to look for invalid characters Extended the basic validation in commit e17c1b25bc33eb to return a failure when invalid base64 characters are included. --- tests/unit/unit1302.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'tests/unit/unit1302.c') diff --git a/tests/unit/unit1302.c b/tests/unit/unit1302.c index b5688f047..6886af8c4 100644 --- a/tests/unit/unit1302.c +++ b/tests/unit/unit1302.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2013, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -31,7 +31,7 @@ static struct SessionHandle *data; static CURLcode unit_setup( void ) { data = curl_easy_init(); - if (!data) + if(!data) return CURLE_OUT_OF_MEMORY; return CURLE_OK; } @@ -128,13 +128,12 @@ fail_unless(rc == CURLE_BAD_CONTENT_ENCODING, "return code should be CURLE_BAD_C 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 */ -size = 0; -decoded = NULL; +/* This is garbage input as it contains an illegal base64 character */ +size = 1; /* not zero */ +decoded = &anychar; /* not 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); +fail_unless(rc == CURLE_BAD_CONTENT_ENCODING, "return code should be CURLE_BAD_CONTENT_ENCODING"); +fail_unless(size == 0, "size should be 0"); +fail_if(decoded, "returned pointer should be NULL"); UNITTEST_STOP -- cgit v1.2.3