1 /*
2 *
3 * honggfuzz - reporting
4 * -----------------------------------------
5 *
6 * Author: Robert Swiecki <swiecki@google.com>
7 *
8 * Copyright 2010-2015 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 "common.h"
25 #include "report.h"
26
27 #include <fcntl.h>
28 #include <inttypes.h>
29 #include <stdio.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
32
33 #include "log.h"
34 #include "util.h"
35
36 static int reportFD = -1;
37
38 #if defined(_HF_ARCH_LINUX)
report_printdynFileMethod(honggfuzz_t * hfuzz)39 static void report_printdynFileMethod(honggfuzz_t * hfuzz)
40 {
41 dprintf(reportFD, " dynFileMethod: ");
42 if (hfuzz->dynFileMethod == 0)
43 dprintf(reportFD, "NONE\n");
44 else {
45 if (hfuzz->dynFileMethod & _HF_DYNFILE_INSTR_COUNT)
46 dprintf(reportFD, "INSTR_COUNT ");
47 if (hfuzz->dynFileMethod & _HF_DYNFILE_BRANCH_COUNT)
48 dprintf(reportFD, "BRANCH_COUNT ");
49 if (hfuzz->dynFileMethod & _HF_DYNFILE_BTS_BLOCK)
50 dprintf(reportFD, "BLOCK_COUNT ");
51 if (hfuzz->dynFileMethod & _HF_DYNFILE_BTS_EDGE)
52 dprintf(reportFD, "EDGE_COUNT ");
53 if (hfuzz->dynFileMethod & _HF_DYNFILE_CUSTOM)
54 dprintf(reportFD, "CUSTOM ");
55
56 dprintf(reportFD, "\n");
57 }
58 }
59 #endif
60
report_printTargetCmd(honggfuzz_t * hfuzz)61 static void report_printTargetCmd(honggfuzz_t * hfuzz)
62 {
63 dprintf(reportFD, " fuzzTarget : ");
64 for (int x = 0; hfuzz->cmdline[x]; x++) {
65 dprintf(reportFD, "%s ", hfuzz->cmdline[x]);
66 }
67 dprintf(reportFD, "\n");
68 }
69
report_Report(honggfuzz_t * hfuzz,char * s)70 void report_Report(honggfuzz_t * hfuzz, char *s)
71 {
72 if (s[0] == '\0') {
73 return;
74 }
75
76 if (reportFD == -1) {
77 char reportFName[PATH_MAX];
78 if (hfuzz->reportFile == NULL) {
79 snprintf(reportFName, sizeof(reportFName), "%s/%s", hfuzz->workDir, _HF_REPORT_FILE);
80 } else {
81 snprintf(reportFName, sizeof(reportFName), "%s", hfuzz->reportFile);
82 }
83
84 reportFD = open(reportFName, O_WRONLY | O_CREAT | O_APPEND, 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 " flipRate : %lf\n"
99 " externalCmd : %s\n"
100 " fuzzStdin : %s\n"
101 " timeout : %ld (sec)\n"
102 " ignoreAddr : %p\n"
103 " memoryLimit : %" PRIu64 " (MiB)\n"
104 " targetPid : %d\n"
105 " targetCmd : %s\n"
106 " wordlistFile : %s\n",
107 localtmstr,
108 hfuzz->origFlipRate,
109 hfuzz->externalCommand == NULL ? "NULL" : hfuzz->externalCommand,
110 hfuzz->fuzzStdin ? "TRUE" : "FALSE",
111 hfuzz->tmOut,
112 hfuzz->ignoreAddr,
113 hfuzz->asLimit,
114 hfuzz->pid, hfuzz->pidCmd,
115 hfuzz->dictionaryFile == NULL ? "NULL" : hfuzz->dictionaryFile);
116
117 #if defined(_HF_ARCH_LINUX)
118 report_printdynFileMethod(hfuzz);
119 #endif
120
121 report_printTargetCmd(hfuzz);
122
123 dprintf(reportFD,
124 "%s" "=====================================================================\n", s);
125 }
126