]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-test: fuzzer - Fix FD-based fuzzing to only shutdown input FD upon end of data.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Mon, 12 Apr 2021 19:14:07 +0000 (21:14 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 15 Apr 2021 06:59:59 +0000 (06:59 +0000)
Before, it closed the whole socket once the data input ended. This for
example caused the SMTP server fuzzer to end before all replies were sent. This
shortened the test and could have hidden bugs that occur later in the SMTP
transaction.

src/lib-test/fuzzer.c
src/lib-test/fuzzer.h

index 8f22621c361dced5abd9ca5e505fc40f457dae0c..bacff3d14f85cd27e88343b19fc8c2833dc8b32c 100644 (file)
@@ -29,6 +29,8 @@ void fuzzer_deinit(struct fuzzer_context *fuzz_ctx)
           if this fails. */
        if (fuzz_ctx->fd > -1)
                (void)close(fuzz_ctx->fd);
+       if (fuzz_ctx->fd_pump > -1)
+               (void)close(fuzz_ctx->fd_pump);
        if (fuzz_ctx->ioloop != NULL)
                io_loop_destroy(&fuzz_ctx->ioloop);
 }
@@ -52,7 +54,7 @@ static void pump_finished(enum iostream_pump_status status ATTR_UNUSED,
                break;
        };
 
-       if (shutdown(o_stream_get_fd(output), SHUT_RDWR) < 0)
+       if (shutdown(o_stream_get_fd(output), SHUT_WR) < 0)
                i_fatal("shutdown() failed: %m");
        iostream_pump_destroy(&fuzz_ctx->pump);
 }
@@ -68,8 +70,9 @@ int fuzzer_io_as_fd(struct fuzzer_context *fuzz_ctx,
        net_set_nonblock(sfd[1], TRUE);
 
        struct istream *input = i_stream_create_from_data(data, size);
-       struct ostream *output = o_stream_create_fd_autoclose(&sfd[0], IO_BLOCK_SIZE);
+       struct ostream *output = o_stream_create_fd(sfd[0], IO_BLOCK_SIZE);
        fuzz_ctx->pump = iostream_pump_create(input, output);
+       fuzz_ctx->fd_pump = sfd[0];
        fuzz_ctx->fd = sfd[1];
        iostream_pump_set_completion_callback(fuzz_ctx->pump, pump_finished,
                                              fuzz_ctx);
index 85d83c4d5e5cbf3cef43944732ce8d281efe0956..e20ba1368b996caf6b79e42a3b11d59e9c0efb88 100644 (file)
@@ -5,7 +5,7 @@ struct iostream_pump;
 struct ioloop;
 
 struct fuzzer_context {
-       int fd;
+       int fd, fd_pump;
        struct iostream_pump *pump;
        struct ioloop *ioloop;
 };