Skip to content

Commit

Permalink
Handle abort(3)
Browse files Browse the repository at this point in the history
  • Loading branch information
plusun committed Jun 20, 2018
1 parent 330d96a commit 3fe4285
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
8 changes: 8 additions & 0 deletions bin/sh/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,17 @@ void
exraise(int e)
{
if (handler == NULL)
#ifndef ENABLE_FUZZER
abort();
#else
fexit();
#endif
exception = e;
#ifdef ENABLE_FUZZER
fexit();
#else
longjmp(handler->loc, 1);
#endif
}


Expand Down
5 changes: 5 additions & 0 deletions bin/sh/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,8 @@ void sh_exit(int) __dead;
#define setjmp(jmploc) _setjmp(jmploc)
#define longjmp(jmploc, val) _longjmp(jmploc, val)
#endif

#ifdef ENABLE_FUZZER
extern jmp_buf fuzzer_exit;
#define fexit() longjmp(fuzzer_exit, 1)
#endif
18 changes: 15 additions & 3 deletions bin/sh/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,24 @@ main(int argc, char **argv)
}
#else
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);

jmp_buf fuzzer_exit;
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
if (Size == 0 || Data[Size - 1] != '\0') {
static const size_t N = 1024;
struct stackmark smark;
if (Size == 0 || Size >= N) {
return 0;
}
evalstring((const char *)Data, 0);
rootshell = 1;
init();
initpwd();
setstackmark(&smark);

line_number = 1;
char buffer[N];
memcpy(buffer, Data, Size);
buffer[Size] = '\0';
if (!setjmp(fuzzer_exit))
evalstring(buffer, 0);
return 0;
}
#endif
Expand Down

0 comments on commit 3fe4285

Please sign in to comment.