|
3 | 3 | #include <string.h>
|
4 | 4 | #include <sys/types.h>
|
5 | 5 |
|
6 |
| -#include "deserialize.h" |
7 |
| -#include "utils.h" |
8 |
| -#include "tx_types.h" |
| 6 | +#include "transaction/deserialize.h" |
| 7 | +#include "transaction/utils.h" |
| 8 | +#include "transaction/tx_types.h" |
9 | 9 | #include "format.h"
|
| 10 | +#include <setjmp.h> |
10 | 11 |
|
| 12 | +jmp_buf fuzz_exit_jump_buf; |
11 | 13 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
12 |
| - buffer_t buf = {.ptr = data, .size = size, .offset = 0}; |
13 |
| - transaction_t tx; |
14 |
| - parser_status_e status; |
15 |
| - char nonce[21] = {0}; |
16 |
| - char address[21] = {0}; |
17 |
| - char amount[21] = {0}; |
18 |
| - char tx_memo[466] = {0}; |
| 14 | + if (setjmp(fuzz_exit_jump_buf) == 0) { |
| 15 | + buffer_t buf = {.ptr = data, .size = size, .offset = 0}; |
| 16 | + transaction_t tx; |
| 17 | + parser_status_e status; |
| 18 | + char nonce[21] = {0}; |
| 19 | + char address[21] = {0}; |
| 20 | + char amount[21] = {0}; |
| 21 | + char tx_memo[466] = {0}; |
19 | 22 |
|
20 |
| - memset(&tx, 0, sizeof(tx)); |
| 23 | + memset(&tx, 0, sizeof(tx)); |
21 | 24 |
|
22 |
| - status = transaction_deserialize(&buf, &tx); |
| 25 | + status = transaction_deserialize(&buf, &tx); |
23 | 26 |
|
24 |
| - if (status == PARSING_OK) { |
25 |
| - format_u64(nonce, sizeof(nonce), tx.nonce); |
26 |
| - printf("nonce: %s\n", nonce); |
27 |
| - format_hex(tx.to, ADDRESS_LEN, address, sizeof(address)); |
28 |
| - printf("address: %s\n", address); |
29 |
| - format_fpu64(amount, sizeof(amount), tx.value, 3); // exponent of smallest unit is 3 |
30 |
| - printf("amount: %s\n", amount); |
31 |
| - transaction_utils_format_memo(tx.memo, tx.memo_len, tx_memo, sizeof(tx_memo)); |
32 |
| - printf("memo: %s\n", tx_memo); |
| 27 | + if (status == PARSING_OK) { |
| 28 | + format_u64(nonce, sizeof(nonce), tx.nonce); |
| 29 | + printf("nonce: %s\n", nonce); |
| 30 | + format_hex(tx.to, ADDRESS_LEN, address, sizeof(address)); |
| 31 | + printf("address: %s\n", address); |
| 32 | + format_fpu64(amount, sizeof(amount), tx.value, 3); // exponent of smallest unit is 3 |
| 33 | + printf("amount: %s\n", amount); |
| 34 | + transaction_utils_format_memo(tx.memo, tx.memo_len, tx_memo, sizeof(tx_memo)); |
| 35 | + printf("memo: %s\n", tx_memo); |
| 36 | + } |
33 | 37 | }
|
34 |
| - |
35 | 38 | return 0;
|
36 | 39 | }
|
0 commit comments