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