From 85c3fe47292f4e4e47a1f58f1347cb1f6d03b37e Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Tue, 20 Oct 2020 15:31:52 +0200 Subject: [BUILD] add option to build the dnbd3-server with afl-fuzz support The afl-fuzz support for the dnbd3-server requires an AFL C compiler like afl-gcc and can be enabled with the CMake option DNBD3_SERVER_AFL. --- src/server/server.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/server/server.c') diff --git a/src/server/server.c b/src/server/server.c index 55ec042..0ee51c4 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -217,6 +217,16 @@ int main(int argc, char *argv[]) { 0, 0, 0, 0 } }; + log_init(); + + /* set proper output stream for AFL */ +#ifdef DNBD3_SERVER_AFL + if ( log_setConsoleOutputStream(stderr) < 0 ) { + logadd( LOG_ERROR, "Failed to set output stream for AFL to stderr" ); + exit( EXIT_FAILURE ); + } +#endif + mainPid = getpid(); mainThread = pthread_self(); opt = getopt_long( argc, argv, optString, longOpts, &longIndex ); @@ -278,6 +288,7 @@ int main(int argc, char *argv[]) opt = getopt_long( argc, argv, optString, longOpts, &longIndex ); } + // Load general config if ( _configDir == NULL ) _configDir = strdup( "/etc/dnbd3-server" ); @@ -291,8 +302,6 @@ int main(int argc, char *argv[]) timing_get( &startupTime ); #ifdef DNBD3_SERVER_AFL - // ###### AFL - // image_serverStartup(); net_init(); uplink_globalsInit(); @@ -316,9 +325,7 @@ int main(int argc, char *argv[]) net_handleNewConnection( dnbd3_client ); exit( 0 ); } - // - // ###### AFL END -#endif +#endif /* DNBD3_SERVER_AFL */ // One-shots first: -- cgit v1.2.3-55-g7522