tests: Rewrite all fuzzers to LLVMFuzzerInitialize and nalloc

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Jakub Jelen
2025-08-12 11:30:54 +02:00
parent 59a502ede6
commit a3c5d3b256
10 changed files with 252 additions and 69 deletions

View File

@@ -14,6 +14,7 @@
* limitations under the License.
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -21,6 +22,8 @@
#define LIBSSH_STATIC 1
#include "libssh/libssh.h"
#include "nallocinc.c"
static void _fuzz_finalize(void)
{
ssh_finalize();
@@ -29,7 +32,8 @@ static void _fuzz_finalize(void)
int LLVMFuzzerInitialize(int *argc, char ***argv)
{
(void)argc;
(void)argv;
nalloc_init(*argv[0]);
ssh_init();
@@ -46,9 +50,11 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
char *signature = NULL;
int rc;
assert(nalloc_start(data, size) > 0);
signature = (char *)malloc(size + 1);
if (signature == NULL) {
return 1;
goto out;
}
strncpy(signature, (const char *)data, size);
signature[size] = '\0';
@@ -56,9 +62,11 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
rc = sshsig_verify(input, sizeof(input), signature, namespace, &pkey);
free(signature);
if (rc != SSH_OK) {
return 1;
goto out;
}
ssh_key_free(pkey);
out:
nalloc_end();
return 0;
}