1 /*
2 *
3 * honggfuzz - reporting
4 * -----------------------------------------
5 *
6 * Author: Robert Swiecki <swiecki@google.com>
7 *
8 * Copyright 2010-2018 by Google Inc. All Rights Reserved.
9 *
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
12 * a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * 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.
21 *
22 */
23
24 #include "report.h"
25
26 #include <errno.h>
27 #include <fcntl.h>
28 #include <inttypes.h>
29 #include <stdio.h>
30 #include <sys/stat.h>
31 #include <sys/types.h>
32
33 #include "libhfcommon/common.h"
34 #include "libhfcommon/log.h"
35 #include "libhfcommon/util.h"
36
37 static int reportFD = -1;
38
39 #if defined(_HF_ARCH_LINUX)
report_printdynFileMethod(run_t * run)40 static void report_printdynFileMethod(run_t* run) {
41 dprintf(reportFD, " dynFileMethod: ");
42 if (run->global->feedback.dynFileMethod == 0)
43 dprintf(reportFD, "NONE\n");
44 else {
45 if (run->global->feedback.dynFileMethod & _HF_DYNFILE_INSTR_COUNT)
46 dprintf(reportFD, "INSTR_COUNT ");
47 if (run->global->feedback.dynFileMethod & _HF_DYNFILE_BRANCH_COUNT)
48 dprintf(reportFD, "BRANCH_COUNT ");
49 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)
52 dprintf(reportFD, "IPT_BLOCK_COUNT ");
53
54 dprintf(reportFD, "\n");
55 }
56 }
57 #endif
58
report_printTargetCmd(run_t * run)59 static void report_printTargetCmd(run_t* run) {
60 dprintf(reportFD, " fuzzTarget : ");
61 for (int x = 0; run->global->exe.cmdline[x]; x++) {
62 dprintf(reportFD, "%s ", run->global->exe.cmdline[x]);
63 }
64 dprintf(reportFD, "\n");
65 }
66
report_Report(run_t * run)67 void report_Report(run_t* run) {
68 if (run->report[0] == '\0') {
69 return;
70 }
71
72 MX_SCOPED_LOCK(&run->global->cfg.report_mutex);
73
74 if (reportFD == -1) {
75 char reportFName[PATH_MAX];
76 if (run->global->cfg.reportFile == NULL) {
77 snprintf(reportFName, sizeof(reportFName), "%s/%s", run->global->io.workDir,
78 _HF_REPORT_FILE);
79 } else {
80 snprintf(reportFName, sizeof(reportFName), "%s", run->global->cfg.reportFile);
81 }
82
83 reportFD =
84 TEMP_FAILURE_RETRY(open(reportFName, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644));
85 if (reportFD == -1) {
86 PLOG_F("Couldn't open('%s') for writing", reportFName);
87 }
88 }
89
90 char localtmstr[PATH_MAX];
91 util_getLocalTime("%F.%H:%M:%S", localtmstr, sizeof(localtmstr), time(NULL));
92
93 dprintf(reportFD,
94 "=====================================================================\n"
95 "TIME: %s\n"
96 "=====================================================================\n"
97 "FUZZER ARGS:\n"
98 " mutationsPerRun : %u\n"
99 " externalCmd : %s\n"
100 " fuzzStdin : %s\n"
101 " timeout : %ld (sec)\n"
102 #if defined(_HF_ARCH_LINUX) || defined(_HF_ARCH_NETBSD)
103 " ignoreAddr : %p\n"
104 #endif
105 " ASLimit : %" PRIu64 " (MiB)\n"
106 " RSSLimit : %" PRIu64 " (MiB)\n"
107 " DATALimit : %" PRIu64 " (MiB)\n"
108 " wordlistFile : %s\n",
109 localtmstr, run->global->mutate.mutationsPerRun,
110 run->global->exe.externalCommand == NULL ? "NULL" : run->global->exe.externalCommand,
111 run->global->exe.fuzzStdin ? "TRUE" : "FALSE", run->global->timing.tmOut,
112 #if defined(_HF_ARCH_LINUX)
113 run->global->linux.ignoreAddr,
114 #elif defined(_HF_ARCH_NETBSD)
115 run->global->netbsd.ignoreAddr,
116 #endif
117 run->global->exe.asLimit, run->global->exe.rssLimit, run->global->exe.dataLimit,
118 run->global->mutate.dictionaryFile == NULL ? "NULL" : run->global->mutate.dictionaryFile);
119
120 #if defined(_HF_ARCH_LINUX)
121 report_printdynFileMethod(run);
122 #endif
123
124 report_printTargetCmd(run);
125
126 dprintf(reportFD,
127 "%s"
128 "=====================================================================\n",
129 run->report);
130 }
131