update common. to fuzz_common.h

Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
This commit is contained in:
Ben Taylor 2025-04-07 15:33:41 +01:00
parent eea3ddaf2c
commit dc027791e9
10 changed files with 9 additions and 79 deletions

View File

@ -31,7 +31,7 @@ foreach(exe IN LISTS executables_no_common_c executables_with_common_c)
$<TARGET_OBJECTS:mbedtls_test_helpers>
$<TARGET_OBJECTS:mbedtls_test>)
if(NOT FUZZINGENGINE_LIB)
list(APPEND exe_sources onefile.c)
list(APPEND exe_sources ${MBEDTLS_DIR}/tf-psa-crypto/programs/fuzz/onefile.c)
endif()
# This emulates "if ( ... IN_LIST ... )" which becomes available in CMake 3.3

View File

@ -4,7 +4,7 @@
#include "mbedtls/entropy.h"
#include "mbedtls/ctr_drbg.h"
#include "test/certs.h"
#include "common.h"
#include "fuzz_common.h"
#include <string.h>
#include <stdlib.h>
#include <stdint.h>

View File

@ -3,7 +3,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include "common.h"
#include "fuzz_common.h"
#include "mbedtls/ssl.h"
#if defined(MBEDTLS_SSL_PROTO_DTLS)
#include "mbedtls/entropy.h"

View File

@ -3,7 +3,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include "common.h"
#include "fuzz_common.h"
#include "mbedtls/ssl.h"
#include "test/certs.h"
#if defined(MBEDTLS_SSL_PROTO_DTLS)

View File

@ -2,7 +2,7 @@
#include <stdint.h>
#include "mbedtls/pkcs7.h"
#include "common.h"
#include "fuzz_common.h"
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
{

View File

@ -5,7 +5,7 @@
#include "mbedtls/ctr_drbg.h"
#include "mbedtls/ssl_ticket.h"
#include "test/certs.h"
#include "common.h"
#include "fuzz_common.h"
#include <string.h>
#include <stdlib.h>
#include <stdint.h>

View File

@ -2,7 +2,7 @@
#include <stdint.h>
#include "mbedtls/x509_crl.h"
#include "common.h"
#include "fuzz_common.h"
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
{

View File

@ -2,7 +2,7 @@
#include <stdint.h>
#include "mbedtls/x509_crt.h"
#include "common.h"
#include "fuzz_common.h"
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
{

View File

@ -2,7 +2,7 @@
#include <stdint.h>
#include "mbedtls/x509_csr.h"
#include "common.h"
#include "fuzz_common.h"
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
{

View File

@ -1,70 +0,0 @@
#define MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include "common.h"
/* This file doesn't use any Mbed TLS function, but grab mbedtls_config.h anyway
* in case it contains platform-specific #defines related to malloc or
* stdio functions. */
#include "mbedtls/build_info.h"
int main(int argc, char **argv)
{
FILE *fp;
uint8_t *Data;
size_t Size;
const char *argv0 = argv[0] == NULL ? "PROGRAM_NAME" : argv[0];
if (argc != 2) {
fprintf(stderr, "Usage: %s REPRODUCER_FILE\n", argv0);
return 1;
}
//opens the file, get its size, and reads it into a buffer
fp = fopen(argv[1], "rb");
if (fp == NULL) {
fprintf(stderr, "%s: Error in fopen\n", argv0);
perror(argv[1]);
return 2;
}
if (fseek(fp, 0L, SEEK_END) != 0) {
fprintf(stderr, "%s: Error in fseek(SEEK_END)\n", argv0);
perror(argv[1]);
fclose(fp);
return 2;
}
Size = ftell(fp);
if (Size == (size_t) -1) {
fprintf(stderr, "%s: Error in ftell\n", argv0);
perror(argv[1]);
fclose(fp);
return 2;
}
if (fseek(fp, 0L, SEEK_SET) != 0) {
fprintf(stderr, "%s: Error in fseek(0)\n", argv0);
perror(argv[1]);
fclose(fp);
return 2;
}
Data = malloc(Size);
if (Data == NULL) {
fprintf(stderr, "%s: Could not allocate memory\n", argv0);
perror(argv[1]);
fclose(fp);
return 2;
}
if (fread(Data, Size, 1, fp) != 1) {
fprintf(stderr, "%s: Error in fread\n", argv0);
perror(argv[1]);
free(Data);
fclose(fp);
return 2;
}
//launch fuzzer
LLVMFuzzerTestOneInput(Data, Size);
free(Data);
fclose(fp);
return 0;
}