-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Arjun <pkillarjun@protonmail.com>
- Loading branch information
1 parent
5134712
commit 5212822
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "maxminddb-compat-util.h" | ||
#include "maxminddb.h" | ||
#include <unistd.h> | ||
|
||
#define kMinInputLength 2 | ||
#define kMaxInputLength 4048 | ||
|
||
extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); | ||
|
||
int | ||
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) | ||
{ | ||
int status; | ||
FILE *fp; | ||
MMDB_s mmdb; | ||
char filename[256]; | ||
|
||
if (size < kMinInputLength || size > kMaxInputLength) | ||
return 0; | ||
|
||
sprintf(filename, "/tmp/libfuzzer.%d", getpid()); | ||
|
||
fp = fopen(filename, "wb"); | ||
if (!fp) | ||
return 0; | ||
|
||
fwrite(data, size, sizeof(uint8_t), fp); | ||
fclose(fp); | ||
|
||
status = MMDB_open(filename, MMDB_MODE_MMAP, &mmdb); | ||
if (status == MMDB_SUCCESS) | ||
MMDB_close(&mmdb); | ||
|
||
unlink(filename); | ||
return 0; | ||
} |