forked from NetBSD/src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fuzzing getdiskcookedname in libutil
- Loading branch information
Showing
2 changed files
with
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# $NetBSD: Makefile,v 1.15 2007/05/28 12:06:25 tls Exp $ | ||
# @(#)Makefile 8.2 (Berkeley) 4/2/94 | ||
|
||
.include <bsd.own.mk> | ||
|
||
PROG= fuzz_getdiskcookedname | ||
SRCS= fuzz_getdiskcookedname.c | ||
.PATH: ${NETBSDSRCDIR}/lib/libutil | ||
SRCS+= getdiskrawname.c | ||
|
||
CFLAGS= -fsanitize=fuzzer-no-link,address,undefined -Wall -Werror | ||
LDFLAGS= -fsanitize=fuzzer,address,undefined -Wall -Werror | ||
|
||
fuzz: fuzz_getdiskcookedname | ||
export UBSAN_OPTIONS=halt_on_error=1 && ./fuzz_getdiskcookedname -only_ascii ./input > /dev/null | ||
|
||
.include <bsd.prog.mk> |
21 changes: 21 additions & 0 deletions
21
tests/fuzz/libutil/getdiskcookedname/fuzz_getdiskcookedname.c
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,21 @@ | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
extern const char * | ||
getdiskcookedname(char *buf, size_t bufsiz, const char *name); | ||
|
||
|
||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | ||
#define N 4096 | ||
char buf[N]; | ||
|
||
char *name = (char *)malloc(size + 1); | ||
memcpy(name, data, size); | ||
name[size] = '\0'; | ||
getdiskcookedname(buf, N, name); | ||
free(name); | ||
|
||
return 0; | ||
} |