| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "alloc-util.h" |
| 4 |
#include "efi-string.h" |
| 5 |
#include "fuzz.h" |
| 6 |
|
| 7 |
typedef struct { |
| 8 |
EFI_STATUS status; |
| 9 |
int16_t field_width; |
| 10 |
int16_t precision; |
| 11 |
const void *ptr; |
| 12 |
char c; |
| 13 |
unsigned char uchar; |
| 14 |
signed char schar; |
| 15 |
unsigned short ushort; |
| 16 |
signed short sshort; |
| 17 |
unsigned int uint; |
| 18 |
signed int sint; |
| 19 |
unsigned long ulong; |
| 20 |
signed long slong; |
| 21 |
unsigned long long ulonglong; |
| 22 |
signed long long slonglong; |
| 23 |
size_t size; |
| 24 |
ssize_t ssize; |
| 25 |
intmax_t intmax; |
| 26 |
uintmax_t uintmax; |
| 27 |
ptrdiff_t ptrdiff; |
| 28 |
char str[]; |
| 29 |
} Input; |
| 30 |
|
| 31 |
#define PRINTF_ONE(...) \ |
| 32 |
({ \ |
| 33 |
_cleanup_free_ char16_t *_ret = xasprintf_status(__VA_ARGS__); \ |
| 34 |
DO_NOT_OPTIMIZE(_ret); \ |
| 35 |
}) |
| 36 |
|
| 37 |
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
| 38 |
if (outside_size_range(size, sizeof(Input), 1024 * 1024)) |
| 39 |
return 0; |
| 40 |
|
| 41 |
const Input *i = (const Input *) data; |
| 42 |
size_t len = size - offsetof(Input, str); |
| 43 |
|
| 44 |
fuzz_setup_logging(); |
| 45 |
|
| 46 |
PRINTF_ONE(i->status, "%*.*s", i->field_width, (int) len, i->str); |
| 47 |
PRINTF_ONE(i->status, "%*.*ls", i->field_width, (int) (len / sizeof(wchar_t)), (const wchar_t *) i->str); |
| 48 |
|
| 49 |
PRINTF_ONE(i->status, "%% %*.*m", i->field_width, i->precision); |
| 50 |
PRINTF_ONE(i->status, "%*p", i->field_width, i->ptr); |
| 51 |
PRINTF_ONE(i->status, "%*c %12340c %56789c", i->field_width, i->c, i->c, i->c); |
| 52 |
|
| 53 |
PRINTF_ONE(i->status, "%*.*hhu", i->field_width, i->precision, i->uchar); |
| 54 |
PRINTF_ONE(i->status, "%*.*hhi", i->field_width, i->precision, i->schar); |
| 55 |
PRINTF_ONE(i->status, "%*.*hu", i->field_width, i->precision, i->ushort); |
| 56 |
PRINTF_ONE(i->status, "%*.*hi", i->field_width, i->precision, i->sshort); |
| 57 |
PRINTF_ONE(i->status, "%*.*u", i->field_width, i->precision, i->uint); |
| 58 |
PRINTF_ONE(i->status, "%*.*i", i->field_width, i->precision, i->sint); |
| 59 |
PRINTF_ONE(i->status, "%*.*lu", i->field_width, i->precision, i->ulong); |
| 60 |
PRINTF_ONE(i->status, "%*.*li", i->field_width, i->precision, i->slong); |
| 61 |
PRINTF_ONE(i->status, "%*.*llu", i->field_width, i->precision, i->ulonglong); |
| 62 |
PRINTF_ONE(i->status, "%*.*lli", i->field_width, i->precision, i->slonglong); |
| 63 |
|
| 64 |
PRINTF_ONE(i->status, "%+*.*hhi", i->field_width, i->precision, i->schar); |
| 65 |
PRINTF_ONE(i->status, "%-*.*hi", i->field_width, i->precision, i->sshort); |
| 66 |
PRINTF_ONE(i->status, "% *.*i", i->field_width, i->precision, i->sint); |
| 67 |
PRINTF_ONE(i->status, "%0*li", i->field_width, i->slong); |
| 68 |
PRINTF_ONE(i->status, "%#*.*llx", i->field_width, i->precision, i->ulonglong); |
| 69 |
|
| 70 |
PRINTF_ONE(i->status, "%-*.*zx", i->field_width, i->precision, i->size); |
| 71 |
PRINTF_ONE(i->status, "% *.*zi", i->field_width, i->precision, i->ssize); |
| 72 |
PRINTF_ONE(i->status, "%0*ji", i->field_width, i->intmax); |
| 73 |
PRINTF_ONE(i->status, "%#0*jX", i->field_width, i->uintmax); |
| 74 |
PRINTF_ONE(i->status, "%*.*ti", i->field_width, i->precision, i->ptrdiff); |
| 75 |
|
| 76 |
return 0; |
| 77 |
} |