diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2017-08-03 07:46:11 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2017-08-03 07:55:06 +0200 |
commit | 7b1f0ab57a596fc2bde709ecf5a2c56f69593b5a (patch) | |
tree | 52387db915d0e53fd8ffa5745efb0f951fdcf43a /devel | |
parent | 1af4f9cf6402acd1ca90cec0b18e60ef85c96f12 (diff) | |
download | gnutls-7b1f0ab57a596fc2bde709ecf5a2c56f69593b5a.tar.gz |
fuzz: introduced mem.h with common callbacks for mem access
Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
Diffstat (limited to 'devel')
-rw-r--r-- | devel/fuzz/gnutls_client_fuzzer.cc | 46 | ||||
-rw-r--r-- | devel/fuzz/gnutls_psk_client_fuzzer.cc | 46 | ||||
-rw-r--r-- | devel/fuzz/gnutls_psk_server_fuzzer.cc | 46 | ||||
-rw-r--r-- | devel/fuzz/gnutls_server_fuzzer.cc | 46 | ||||
-rw-r--r-- | devel/fuzz/gnutls_srp_client_fuzzer.cc | 46 | ||||
-rw-r--r-- | devel/fuzz/gnutls_srp_server_fuzzer.cc | 46 | ||||
-rw-r--r-- | devel/fuzz/mem.h | 67 |
7 files changed, 91 insertions, 252 deletions
diff --git a/devel/fuzz/gnutls_client_fuzzer.cc b/devel/fuzz/gnutls_client_fuzzer.cc index 8ed8f299d5..b9c22200e6 100644 --- a/devel/fuzz/gnutls_client_fuzzer.cc +++ b/devel/fuzz/gnutls_client_fuzzer.cc @@ -26,45 +26,7 @@ #include <stdlib.h> #include <gnutls/gnutls.h> - -struct mem_st { - const uint8_t *data; - size_t size; -}; - -#define MIN(x,y) ((x)<(y)?(x):(y)) -static ssize_t -client_push(gnutls_transport_ptr_t tr, const void *data, size_t len) -{ - return len; -} - -static ssize_t client_pull(gnutls_transport_ptr_t tr, void *data, size_t len) -{ - struct mem_st *p = (struct mem_st *)tr; - - if (p->size == 0) { - return 0; - } - - len = MIN(len, p->size); - memcpy(data, p->data, len); - - p->size -= len; - p->data += len; - - return len; -} - -int client_pull_timeout_func(gnutls_transport_ptr_t tr, unsigned int ms) -{ - struct mem_st *p = (struct mem_st *)tr; - - if (p->size > 0) - return 1; /* available data */ - else - return 0; /* timeout */ -} +#include "mem.h" #ifdef __cplusplus extern "C" @@ -90,10 +52,10 @@ int LLVMFuzzerTestOneInput(const uint8_t * data, size_t size) memdata.data = data; memdata.size = size; - gnutls_transport_set_push_function(session, client_push); - gnutls_transport_set_pull_function(session, client_pull); + gnutls_transport_set_push_function(session, mem_push); + gnutls_transport_set_pull_function(session, mem_pull); gnutls_transport_set_pull_timeout_function(session, - client_pull_timeout_func); + mem_pull_timeout); gnutls_transport_set_ptr(session, &memdata); do { diff --git a/devel/fuzz/gnutls_psk_client_fuzzer.cc b/devel/fuzz/gnutls_psk_client_fuzzer.cc index 35b85f64c5..0d622dcf8e 100644 --- a/devel/fuzz/gnutls_psk_client_fuzzer.cc +++ b/devel/fuzz/gnutls_psk_client_fuzzer.cc @@ -32,45 +32,7 @@ #include <gnutls/gnutls.h> #include "psk.h" - -struct mem_st { - const uint8_t *data; - size_t size; -}; - -#define MIN(x,y) ((x)<(y)?(x):(y)) -static ssize_t -client_push(gnutls_transport_ptr_t tr, const void *data, size_t len) -{ - return len; -} - -static ssize_t client_pull(gnutls_transport_ptr_t tr, void *data, size_t len) -{ - struct mem_st *p = (struct mem_st *)tr; - - if (p->size == 0) { - return 0; - } - - len = MIN(len, p->size); - memcpy(data, p->data, len); - - p->size -= len; - p->data += len; - - return len; -} - -int client_pull_timeout_func(gnutls_transport_ptr_t tr, unsigned int ms) -{ - struct mem_st *p = (struct mem_st *)tr; - - if (p->size > 0) - return 1; /* available data */ - else - return 0; /* timeout */ -} +#include "mem.h" #ifdef __cplusplus extern "C" @@ -104,10 +66,10 @@ int LLVMFuzzerTestOneInput(const uint8_t * data, size_t size) memdata.data = data; memdata.size = size; - gnutls_transport_set_push_function(session, client_push); - gnutls_transport_set_pull_function(session, client_pull); + gnutls_transport_set_push_function(session, mem_push); + gnutls_transport_set_pull_function(session, mem_pull); gnutls_transport_set_pull_timeout_function(session, - client_pull_timeout_func); + mem_pull_timeout); gnutls_transport_set_ptr(session, &memdata); do { diff --git a/devel/fuzz/gnutls_psk_server_fuzzer.cc b/devel/fuzz/gnutls_psk_server_fuzzer.cc index 60b8a94710..d54cf068cd 100644 --- a/devel/fuzz/gnutls_psk_server_fuzzer.cc +++ b/devel/fuzz/gnutls_psk_server_fuzzer.cc @@ -31,45 +31,7 @@ #include "certs.h" #include "psk.h" - -struct mem_st { - const uint8_t *data; - size_t size; -}; - -#define MIN(x,y) ((x)<(y)?(x):(y)) -static ssize_t -server_push(gnutls_transport_ptr_t tr, const void *data, size_t len) -{ - return len; -} - -static ssize_t server_pull(gnutls_transport_ptr_t tr, void *data, size_t len) -{ - struct mem_st *p = (struct mem_st*)tr; - - if (p->size == 0) { - return 0; - } - - len = MIN(len, p->size); - memcpy(data, p->data, len); - - p->size -= len; - p->data += len; - - return len; -} - -int server_pull_timeout_func(gnutls_transport_ptr_t tr, unsigned int ms) -{ - struct mem_st *p = (struct mem_st*)tr; - - if (p->size > 0) - return 1; /* available data */ - else - return 0; /* timeout */ -} +#include "mem.h" static int psk_cb(gnutls_session_t session, const char *username, @@ -143,9 +105,9 @@ int LLVMFuzzerTestOneInput(const uint8_t * data, size_t size) memdata.data = data; memdata.size = size; - gnutls_transport_set_push_function(session, server_push); - gnutls_transport_set_pull_function(session, server_pull); - gnutls_transport_set_pull_timeout_function(session, server_pull_timeout_func); + gnutls_transport_set_push_function(session, mem_push); + gnutls_transport_set_pull_function(session, mem_pull); + gnutls_transport_set_pull_timeout_function(session, mem_pull_timeout); gnutls_transport_set_ptr(session, &memdata); do { diff --git a/devel/fuzz/gnutls_server_fuzzer.cc b/devel/fuzz/gnutls_server_fuzzer.cc index 595548e739..de12fdcb7d 100644 --- a/devel/fuzz/gnutls_server_fuzzer.cc +++ b/devel/fuzz/gnutls_server_fuzzer.cc @@ -25,45 +25,7 @@ #include <gnutls/gnutls.h> #include "certs.h" - -struct mem_st { - const uint8_t *data; - size_t size; -}; - -#define MIN(x,y) ((x)<(y)?(x):(y)) -static ssize_t -server_push(gnutls_transport_ptr_t tr, const void *data, size_t len) -{ - return len; -} - -static ssize_t server_pull(gnutls_transport_ptr_t tr, void *data, size_t len) -{ - struct mem_st *p = (struct mem_st*)tr; - - if (p->size == 0) { - return 0; - } - - len = MIN(len, p->size); - memcpy(data, p->data, len); - - p->size -= len; - p->data += len; - - return len; -} - -int server_pull_timeout_func(gnutls_transport_ptr_t tr, unsigned int ms) -{ - struct mem_st *p = (struct mem_st*)tr; - - if (p->size > 0) - return 1; /* available data */ - else - return 0; /* timeout */ -} +#include "mem.h" #ifdef __cplusplus extern "C" @@ -114,9 +76,9 @@ int LLVMFuzzerTestOneInput(const uint8_t * data, size_t size) memdata.data = data; memdata.size = size; - gnutls_transport_set_push_function(session, server_push); - gnutls_transport_set_pull_function(session, server_pull); - gnutls_transport_set_pull_timeout_function(session, server_pull_timeout_func); + gnutls_transport_set_push_function(session, mem_push); + gnutls_transport_set_pull_function(session, mem_pull); + gnutls_transport_set_pull_timeout_function(session, mem_pull_timeout); gnutls_transport_set_ptr(session, &memdata); do { diff --git a/devel/fuzz/gnutls_srp_client_fuzzer.cc b/devel/fuzz/gnutls_srp_client_fuzzer.cc index e3944eb33b..c1923605a8 100644 --- a/devel/fuzz/gnutls_srp_client_fuzzer.cc +++ b/devel/fuzz/gnutls_srp_client_fuzzer.cc @@ -32,45 +32,7 @@ #include <gnutls/gnutls.h> #include "srp.h" - -struct mem_st { - const uint8_t *data; - size_t size; -}; - -#define MIN(x,y) ((x)<(y)?(x):(y)) -static ssize_t -client_push(gnutls_transport_ptr_t tr, const void *data, size_t len) -{ - return len; -} - -static ssize_t client_pull(gnutls_transport_ptr_t tr, void *data, size_t len) -{ - struct mem_st *p = (struct mem_st *)tr; - - if (p->size == 0) { - return 0; - } - - len = MIN(len, p->size); - memcpy(data, p->data, len); - - p->size -= len; - p->data += len; - - return len; -} - -int client_pull_timeout_func(gnutls_transport_ptr_t tr, unsigned int ms) -{ - struct mem_st *p = (struct mem_st *)tr; - - if (p->size > 0) - return 1; /* available data */ - else - return 0; /* timeout */ -} +#include "mem.h" #ifdef __cplusplus extern "C" @@ -100,10 +62,10 @@ int LLVMFuzzerTestOneInput(const uint8_t * data, size_t size) memdata.data = data; memdata.size = size; - gnutls_transport_set_push_function(session, client_push); - gnutls_transport_set_pull_function(session, client_pull); + gnutls_transport_set_push_function(session, mem_push); + gnutls_transport_set_pull_function(session, mem_pull); gnutls_transport_set_pull_timeout_function(session, - client_pull_timeout_func); + mem_pull_timeout); gnutls_transport_set_ptr(session, &memdata); do { diff --git a/devel/fuzz/gnutls_srp_server_fuzzer.cc b/devel/fuzz/gnutls_srp_server_fuzzer.cc index aacb26a9b5..e58cfa413d 100644 --- a/devel/fuzz/gnutls_srp_server_fuzzer.cc +++ b/devel/fuzz/gnutls_srp_server_fuzzer.cc @@ -31,45 +31,7 @@ #include "certs.h" #include "srp.h" - -struct mem_st { - const uint8_t *data; - size_t size; -}; - -#define MIN(x,y) ((x)<(y)?(x):(y)) -static ssize_t -server_push(gnutls_transport_ptr_t tr, const void *data, size_t len) -{ - return len; -} - -static ssize_t server_pull(gnutls_transport_ptr_t tr, void *data, size_t len) -{ - struct mem_st *p = (struct mem_st*)tr; - - if (p->size == 0) { - return 0; - } - - len = MIN(len, p->size); - memcpy(data, p->data, len); - - p->size -= len; - p->data += len; - - return len; -} - -int server_pull_timeout_func(gnutls_transport_ptr_t tr, unsigned int ms) -{ - struct mem_st *p = (struct mem_st*)tr; - - if (p->size > 0) - return 1; /* available data */ - else - return 0; /* timeout */ -} +#include "mem.h" static int srp_cb(gnutls_session_t session, const char *username, @@ -154,9 +116,9 @@ int LLVMFuzzerTestOneInput(const uint8_t * data, size_t size) memdata.data = data; memdata.size = size; - gnutls_transport_set_push_function(session, server_push); - gnutls_transport_set_pull_function(session, server_pull); - gnutls_transport_set_pull_timeout_function(session, server_pull_timeout_func); + gnutls_transport_set_push_function(session, mem_push); + gnutls_transport_set_pull_function(session, mem_pull); + gnutls_transport_set_pull_timeout_function(session, mem_pull_timeout); gnutls_transport_set_ptr(session, &memdata); do { diff --git a/devel/fuzz/mem.h b/devel/fuzz/mem.h new file mode 100644 index 0000000000..5a49b56971 --- /dev/null +++ b/devel/fuzz/mem.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2017 Nikos Mavrogiannopoulos + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef MEM_H +# define MEM_H + +typedef struct mem_st { + const uint8_t *data; + size_t size; +} mem_st; + +#define MIN(x,y) ((x)<(y)?(x):(y)) +static ssize_t +mem_push(gnutls_transport_ptr_t tr, const void *data, size_t len) +{ + return len; +} + +static ssize_t mem_pull(gnutls_transport_ptr_t tr, void *data, size_t len) +{ + struct mem_st *p = (struct mem_st *)tr; + + if (p->size == 0) { + return 0; + } + + len = MIN(len, p->size); + memcpy(data, p->data, len); + + p->size -= len; + p->data += len; + + return len; +} + +static +int mem_pull_timeout(gnutls_transport_ptr_t tr, unsigned int ms) +{ + struct mem_st *p = (struct mem_st *)tr; + + if (p->size > 0) + return 1; /* available data */ + else + return 0; /* timeout */ +} + +#endif |