Skip to content

Commit

Permalink
Fuzzing getdiskcookedname in libutil
Browse files Browse the repository at this point in the history
  • Loading branch information
plusun committed Aug 1, 2018
1 parent 37e30c1 commit 99fa066
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/fuzz/libutil/getdiskcookedname/Makefile
@@ -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 tests/fuzz/libutil/getdiskcookedname/fuzz_getdiskcookedname.c
@@ -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;
}

0 comments on commit 99fa066

Please sign in to comment.