mirror of
https://github.com/acidanthera/OpenCorePkg.git
synced 2025-12-08 19:25:01 +00:00
Revert "Deprecate OcBase64Decode in favor of edk2's Base64Decode" This reverts commit 2104029260a009b807614b10aaee931685840282. Reference: https://github.com/acidanthera/bugtracker/issues/372
94 lines
3.0 KiB
C
94 lines
3.0 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 <Library/OcTemplateLib.h>
|
|
#include <Library/OcSerializeLib.h>
|
|
#include <Library/OcMiscLib.h>
|
|
#include <Library/OcConfigurationLib.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
/*
|
|
clang -g -fsanitize=undefined,address -I../Include -I../../Include -I../../../MdePkg/Include/ -I../../../EfiPkg/Include/ -include ../Include/Base.h Serialized.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 Serialized
|
|
|
|
for fuzzing:
|
|
clang-mp-7.0 -Dmain=__main -g -fsanitize=undefined,address,fuzzer -I../Include -I../../Include -I../../../MdePkg/Include/ -include ../Include/Base.h Serialized.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 Serialized
|
|
rm -rf DICT fuzz*.log ; mkdir DICT ; cp Serialized.plist DICT ; ./Serialized -jobs=4 DICT
|
|
|
|
rm -rf Serialized.dSYM DICT fuzz*.log Serialized
|
|
*/
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
uint8_t *readFile(const char *str, uint32_t *size) {
|
|
FILE *f = fopen(str, "rb");
|
|
|
|
if (!f) return NULL;
|
|
|
|
fseek(f, 0, SEEK_END);
|
|
long fsize = ftell(f);
|
|
fseek(f, 0, SEEK_SET);
|
|
|
|
uint8_t *string = malloc(fsize + 1);
|
|
fread(string, fsize, 1, f);
|
|
fclose(f);
|
|
|
|
string[fsize] = 0;
|
|
*size = fsize;
|
|
|
|
return string;
|
|
}
|
|
|
|
int main(int argc, char** argv) {
|
|
uint32_t f;
|
|
uint8_t *b;
|
|
if ((b = readFile(argc > 1 ? argv[1] : "Serialized.plist", &f)) == NULL) {
|
|
printf("Read fail\n");
|
|
return -1;
|
|
}
|
|
|
|
long long a = current_timestamp();
|
|
|
|
OC_GLOBAL_CONFIG Config;
|
|
EFI_STATUS Status = OcConfigurationInit (&Config, b, f);
|
|
|
|
DEBUG((EFI_D_ERROR, "Done in %llu ms\n", 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;
|
|
}
|
|
|