added better error handling to forkserver fd

This commit is contained in:
Dominik Maier
2020-11-03 13:41:06 +01:00
parent 350c3b323a
commit d795ec0451
3 changed files with 20 additions and 10 deletions

5
.gitignore vendored
View File

@ -76,3 +76,8 @@ examples/afl_frida/afl-frida
examples/afl_frida/libtestinstr.so examples/afl_frida/libtestinstr.so
examples/afl_frida/frida-gum-example.c examples/afl_frida/frida-gum-example.c
examples/afl_frida/frida-gum.h examples/afl_frida/frida-gum.h
examples/aflpp_driver/libAFLDriver.a
examples/aflpp_driver/libAFLQemuDriver.a
libAFLDriver.a
libAFLQemuDriver.a
test/.afl_performance

View File

@ -273,13 +273,15 @@
/* Error-checking versions of read() and write() that call RPFATAL() as /* Error-checking versions of read() and write() that call RPFATAL() as
appropriate. */ appropriate. */
#define ck_write(fd, buf, len, fn) \ #define ck_write(fd, buf, len, fn) \
do { \ do { \
\ \
s32 _len = (s32)(len); \ int _fd = (fd); \
s32 _res = write(fd, buf, _len); \ \
if (_res != _len) RPFATAL(_res, "Short write to %s", fn); \ s32 _len = (s32)(len); \
\ s32 _res = write(_fd, (buf), _len); \
if (_res != _len) RPFATAL(_res, "Short write to %s, fd %d", fn, _fd); \
\
} while (0) } while (0)
#define ck_read(fd, buf, len, fn) \ #define ck_read(fd, buf, len, fn) \

View File

@ -983,10 +983,13 @@ void afl_fsrv_write_to_testcase(afl_forkserver_t *fsrv, u8 *buf, size_t len) {
if (fd < 0) { PFATAL("Unable to create '%s'", fsrv->out_file); } if (fd < 0) { PFATAL("Unable to create '%s'", fsrv->out_file); }
} else if (unlikely(!fd)) { } else if (unlikely(fd <= 0)) {
// We should never have stdin as fd here, 0 is likely unset. // We should have a (non-stdin) fd at this point, else we got a problem.
FATAL("Nowhere to write output to (neither out_fd nor out_file set)"); FATAL(
"Nowhere to write output to (neither out_fd nor out_file set (fd is "
"%d))",
fd);
} else { } else {