mirror of
https://github.com/acidanthera/OpenCorePkg.git
synced 2025-12-08 19:25:01 +00:00
79 lines
2.5 KiB
C
79 lines
2.5 KiB
C
/** @file
|
|
Copyright (C) 2018, vit9696. All rights reserved.
|
|
|
|
All rights reserved.
|
|
|
|
This program and the accompanying materials
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
**/
|
|
|
|
#include <Uefi.h>
|
|
#include <Library/UefiLib.h>
|
|
#include <Library/UefiApplicationEntryPoint.h>
|
|
#include <Library/UefiBootServicesTableLib.h>
|
|
#include <Library/MemoryAllocationLib.h>
|
|
|
|
#include <Library/OcTemplateLib.h>
|
|
#include <Library/OcSerializeLib.h>
|
|
#include <Library/OcMiscLib.h>
|
|
#include <Library/OcConfigurationLib.h>
|
|
|
|
#include <File.h>
|
|
#include <sys/time.h>
|
|
|
|
/*
|
|
for fuzzing (TODO):
|
|
clang-mp-7.0 -Dmain=__main -g -fsanitize=undefined,address,fuzzer -I../Include -I../../Include -I../../../MdePkg/Include/ -include ../Include/Base.h ConfigValidty.c ../../Library/OcXmlLib/OcXmlLib.c ../../Library/OcTemplateLib/OcTemplateLib.c ../../Library/OcSerializeLib/OcSerializeLib.c ../../Library/OcMiscLib/Base64Decode.c ../../Library/OcStringLib/OcAsciiLib.c ../../Library/OcConfigurationLib/OcConfigurationLib.c -o ConfigValidty
|
|
rm -rf DICT fuzz*.log ; mkdir DICT ; cp ConfigValidty.plist DICT ; ./ConfigValidty -jobs=4 DICT
|
|
|
|
rm -rf ConfigValidty.dSYM DICT fuzz*.log ConfigValidty
|
|
*/
|
|
|
|
|
|
long long current_timestamp() {
|
|
struct timeval te;
|
|
gettimeofday(&te, NULL); // get current time
|
|
long long milliseconds = te.tv_sec*1000LL + te.tv_usec/1000; // calculate milliseconds
|
|
// printf("milliseconds: %lld\n", milliseconds);
|
|
return milliseconds;
|
|
}
|
|
|
|
int main(int argc, char** argv) {
|
|
uint32_t f;
|
|
uint8_t *b;
|
|
if ((b = readFile(argc > 1 ? argv[1] : "config.plist", &f)) == NULL) {
|
|
printf("Read fail\n");
|
|
return -1;
|
|
}
|
|
|
|
long long a = current_timestamp();
|
|
|
|
OC_GLOBAL_CONFIG Config;
|
|
OcConfigurationInit (&Config, b, f);
|
|
|
|
DEBUG ((DEBUG_ERROR, "Done checking %a in %llu ms\n", argc > 1 ? argv[1] : "./config.plist", current_timestamp() - a));
|
|
|
|
OcConfigurationFree (&Config);
|
|
|
|
free(b);
|
|
|
|
return 0;
|
|
}
|
|
|
|
INT32 LLVMFuzzerTestOneInput(CONST UINT8 *Data, UINTN Size) {
|
|
VOID *NewData = AllocatePool (Size);
|
|
if (NewData) {
|
|
CopyMem (NewData, Data, Size);
|
|
OC_GLOBAL_CONFIG Config;
|
|
OcConfigurationInit (&Config, NewData, Size);
|
|
OcConfigurationFree (&Config);
|
|
FreePool (NewData);
|
|
}
|
|
return 0;
|
|
}
|