|
| 1 | +/*************************************************************************** |
| 2 | + * _ _ ____ _ |
| 3 | + * Project ___| | | | _ \| | |
| 4 | + * / __| | | | |_) | | |
| 5 | + * | (__| |_| | _ <| |___ |
| 6 | + * \___|\___/|_| \_\_____| |
| 7 | + * |
| 8 | + * Copyright (C) 2017, Max Dymond, <cmeister2@gmail.com>, et al. |
| 9 | + * |
| 10 | + * This software is licensed as described in the file COPYING, which |
| 11 | + * you should have received as part of this distribution. The terms |
| 12 | + * are also available at https://curl.se/docs/copyright.html. |
| 13 | + * |
| 14 | + * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
| 15 | + * copies of the Software, and permit persons to whom the Software is |
| 16 | + * furnished to do so, under the terms of the COPYING file. |
| 17 | + * |
| 18 | + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 19 | + * KIND, either express or implied. |
| 20 | + * |
| 21 | + ***************************************************************************/ |
| 22 | + |
| 23 | +extern "C" |
| 24 | +{ |
| 25 | + #include <stdlib.h> |
| 26 | + #include <signal.h> |
| 27 | + #include <string.h> |
| 28 | + #include <unistd.h> |
| 29 | + #include <inttypes.h> |
| 30 | + #include <curl/curl.h> |
| 31 | + #include "curl/lib/curl_base64.h" |
| 32 | + #include "curl/lib/curl_printf.h" |
| 33 | + #include "curl/lib/curl_memory.h" |
| 34 | + #include "curl/lib/memdebug.h" |
| 35 | + #include <assert.h> |
| 36 | +} |
| 37 | + |
| 38 | +#include <string> |
| 39 | + |
| 40 | +/* #define DEBUG(STMT) STMT */ |
| 41 | +#define DEBUG(STMT) |
| 42 | + |
| 43 | + |
| 44 | +void curl_dbg_free(void *ptr) |
| 45 | +{ |
| 46 | + if(ptr) { |
| 47 | + void *mem = (void *)((char *)ptr - 8); |
| 48 | + |
| 49 | + /* free for real */ |
| 50 | + (Curl_cfree)(mem); |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | + |
| 55 | +/** |
| 56 | + * Fuzzing entry point. This function is passed a buffer containing a test |
| 57 | + * case. This test case should drive the CURL fnmatch function. |
| 58 | + */ |
| 59 | +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
| 60 | +{ |
| 61 | + std::string s(reinterpret_cast<const char*>(data), size); |
| 62 | + CURLcode fnrc; |
| 63 | + unsigned char *outptr = NULL, *outptr2 = NULL; |
| 64 | + char *recodeptr = NULL; |
| 65 | + size_t inlen = strlen(s.c_str()), outlen, outlen2, recodelen; |
| 66 | + |
| 67 | + fnrc = Curl_base64_decode(s.c_str(), &outptr, &outlen); |
| 68 | + |
| 69 | + (void)fnrc; |
| 70 | + DEBUG(printf("Curl_base64_decode returned %d with %s\n", fnrc, s.c_str())); |
| 71 | + |
| 72 | + if (fnrc != CURLE_OK) |
| 73 | + goto EXIT_LABEL; |
| 74 | + |
| 75 | + fnrc = Curl_base64_encode((const char *)outptr, outlen, &recodeptr, &recodelen); |
| 76 | + |
| 77 | + if (fnrc != CURLE_OK) |
| 78 | + goto EXIT_LABEL; |
| 79 | + |
| 80 | + (void)fnrc; |
| 81 | + DEBUG(printf("Curl_base64_encode returned %d with %s\n", fnrc, s.c_str())); |
| 82 | + |
| 83 | + fnrc = Curl_base64_decode(recodeptr, &outptr2, &outlen2); |
| 84 | + |
| 85 | + DEBUG(printf("Sizes og:%lu decode:%lu recode:%lu decode2:%lu, Strings '%s' '%s'\n", inlen, outlen, recodelen, outlen2, s.c_str(), recodeptr)); |
| 86 | + |
| 87 | + assert(fnrc == CURLE_OK); |
| 88 | + assert(outlen == outlen2); |
| 89 | + assert(!memcmp(outptr, outptr2, outlen)); |
| 90 | + |
| 91 | +EXIT_LABEL: |
| 92 | + |
| 93 | + curl_dbg_free(outptr); |
| 94 | + curl_dbg_free(outptr2); |
| 95 | + curl_dbg_free(recodeptr); |
| 96 | + |
| 97 | + return 0; |
| 98 | +} |
0 commit comments