blob: 034a1868bf329db403682440e65dff08bc007b2e [file] [log] [blame]
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +00001/*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +00002 *
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +00003 * honggfuzz - reporting
4 * -----------------------------------------
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +00005 *
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +00006 * Author: Robert Swiecki <swiecki@google.com>
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +00007 *
Robert Swiecki46288f72018-02-27 17:28:47 +01008 * Copyright 2010-2018 by Google Inc. All Rights Reserved.
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +00009 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License. You may obtain
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000012 * a copy of the License at
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +000013 *
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000014 * http://www.apache.org/licenses/LICENSE-2.0
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +000015 *
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000016 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
19 * implied. See the License for the specific language governing
20 * permissions and limitations under the License.
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +000021 *
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000022 */
23
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000024#include "report.h"
25
Robert Swieckiaf7a92b2019-04-17 22:02:53 +020026#include <errno.h>
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000027#include <fcntl.h>
Jagger921bf562015-09-08 22:05:47 +020028#include <inttypes.h>
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000029#include <stdio.h>
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000030#include <sys/stat.h>
Robert Swieckid0fa62c2017-09-28 18:11:05 +020031#include <sys/types.h>
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000032
Robert Swiecki246af3e2018-01-05 14:56:32 +010033#include "libhfcommon/common.h"
34#include "libhfcommon/log.h"
35#include "libhfcommon/util.h"
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000036
37static int reportFD = -1;
38
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030039#if defined(_HF_ARCH_LINUX)
Robert Swieckid50ed422017-11-13 23:32:26 +010040static void report_printdynFileMethod(run_t* run) {
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030041 dprintf(reportFD, " dynFileMethod: ");
Robert Swieckia5b918a2018-03-07 23:59:53 +010042 if (run->global->feedback.dynFileMethod == 0)
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030043 dprintf(reportFD, "NONE\n");
44 else {
Robert Swieckia5b918a2018-03-07 23:59:53 +010045 if (run->global->feedback.dynFileMethod & _HF_DYNFILE_INSTR_COUNT)
46 dprintf(reportFD, "INSTR_COUNT ");
47 if (run->global->feedback.dynFileMethod & _HF_DYNFILE_BRANCH_COUNT)
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030048 dprintf(reportFD, "BRANCH_COUNT ");
Robert Swieckia5b918a2018-03-07 23:59:53 +010049 if (run->global->feedback.dynFileMethod & _HF_DYNFILE_BTS_EDGE)
50 dprintf(reportFD, "BTS_EDGE_COUNT ");
51 if (run->global->feedback.dynFileMethod & _HF_DYNFILE_IPT_BLOCK)
Robert Swiecki6134ce02017-06-14 14:58:37 +020052 dprintf(reportFD, "IPT_BLOCK_COUNT ");
Anestis Bechtsoudisf9f4a852015-08-18 14:30:02 +030053
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030054 dprintf(reportFD, "\n");
55 }
56}
57#endif
58
Robert Swieckid50ed422017-11-13 23:32:26 +010059static void report_printTargetCmd(run_t* run) {
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030060 dprintf(reportFD, " fuzzTarget : ");
Robert Swiecki97d0cee2017-12-18 00:17:50 +010061 for (int x = 0; run->global->exe.cmdline[x]; x++) {
62 dprintf(reportFD, "%s ", run->global->exe.cmdline[x]);
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030063 }
64 dprintf(reportFD, "\n");
65}
66
Robert Swieckid50ed422017-11-13 23:32:26 +010067void report_Report(run_t* run) {
Robert Swieckid440cbb2017-11-14 00:47:11 +010068 if (run->report[0] == '\0') {
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000069 return;
70 }
71
Robert Swieckia5b918a2018-03-07 23:59:53 +010072 MX_SCOPED_LOCK(&run->global->cfg.report_mutex);
Robert Swiecki216fef62016-10-20 18:32:58 +020073
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000074 if (reportFD == -1) {
Jagger55e3bee2015-09-10 00:07:23 +020075 char reportFName[PATH_MAX];
Robert Swieckia5b918a2018-03-07 23:59:53 +010076 if (run->global->cfg.reportFile == NULL) {
Robert Swiecki82c707c2017-11-14 16:36:23 +010077 snprintf(reportFName, sizeof(reportFName), "%s/%s", run->global->io.workDir,
78 _HF_REPORT_FILE);
Jagger55e3bee2015-09-10 00:07:23 +020079 } else {
Robert Swieckia5b918a2018-03-07 23:59:53 +010080 snprintf(reportFName, sizeof(reportFName), "%s", run->global->cfg.reportFile);
Jagger55e3bee2015-09-10 00:07:23 +020081 }
82
Robert Swieckiaf7a92b2019-04-17 22:02:53 +020083 reportFD =
84 TEMP_FAILURE_RETRY(open(reportFName, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644));
Jagger55e3bee2015-09-10 00:07:23 +020085 if (reportFD == -1) {
Robert Swieckic8c32db2015-10-09 18:06:22 +020086 PLOG_F("Couldn't open('%s') for writing", reportFName);
Jagger55e3bee2015-09-10 00:07:23 +020087 }
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000088 }
89
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000090 char localtmstr[PATH_MAX];
Robert Swiecki81c6a0d2015-09-08 15:43:20 +020091 util_getLocalTime("%F.%H:%M:%S", localtmstr, sizeof(localtmstr), time(NULL));
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000092
93 dprintf(reportFD,
Robert Swiecki4e595fb2017-10-11 17:26:51 +020094 "=====================================================================\n"
95 "TIME: %s\n"
96 "=====================================================================\n"
97 "FUZZER ARGS:\n"
Robert Swiecki10e93562017-11-04 00:57:47 +010098 " mutationsPerRun : %u\n"
99 " externalCmd : %s\n"
100 " fuzzStdin : %s\n"
101 " timeout : %ld (sec)\n"
Kamil Rytarowskibdfe2a72018-08-18 12:28:29 +0200102#if defined(_HF_ARCH_LINUX) || defined(_HF_ARCH_NETBSD)
Robert Swiecki10e93562017-11-04 00:57:47 +0100103 " ignoreAddr : %p\n"
Kamil Rytarowskib2d550a2018-08-10 14:43:56 +0200104#endif
Robert Swiecki98e23372019-01-30 11:50:18 +0100105 " ASLimit : %" PRIu64 " (MiB)\n"
106 " RSSLimit : %" PRIu64 " (MiB)\n"
107 " DATALimit : %" PRIu64 " (MiB)\n"
Robert Swiecki10e93562017-11-04 00:57:47 +0100108 " wordlistFile : %s\n",
Robert Swiecki04dcac32018-03-02 03:05:26 +0100109 localtmstr, run->global->mutate.mutationsPerRun,
Robert Swiecki97d0cee2017-12-18 00:17:50 +0100110 run->global->exe.externalCommand == NULL ? "NULL" : run->global->exe.externalCommand,
Robert Swiecki371e1292017-12-18 01:10:33 +0100111 run->global->exe.fuzzStdin ? "TRUE" : "FALSE", run->global->timing.tmOut,
Kamil Rytarowskib2d550a2018-08-10 14:43:56 +0200112#if defined(_HF_ARCH_LINUX)
113 run->global->linux.ignoreAddr,
Kamil Rytarowskibdfe2a72018-08-18 12:28:29 +0200114#elif defined(_HF_ARCH_NETBSD)
115 run->global->netbsd.ignoreAddr,
Kamil Rytarowskib2d550a2018-08-10 14:43:56 +0200116#endif
117 run->global->exe.asLimit, run->global->exe.rssLimit, run->global->exe.dataLimit,
Robert Swiecki04dcac32018-03-02 03:05:26 +0100118 run->global->mutate.dictionaryFile == NULL ? "NULL" : run->global->mutate.dictionaryFile);
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300119
120#if defined(_HF_ARCH_LINUX)
Robert Swiecki78633d12017-11-13 23:24:55 +0100121 report_printdynFileMethod(run);
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300122#endif
123
Robert Swiecki78633d12017-11-13 23:24:55 +0100124 report_printTargetCmd(run);
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300125
126 dprintf(reportFD,
Robert Swiecki4e595fb2017-10-11 17:26:51 +0200127 "%s"
128 "=====================================================================\n",
Robert Swiecki78633d12017-11-13 23:24:55 +0100129 run->report);
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +0000130}