blob: b9ddb59a76850b677bf5c9d7c4eb2d42c99e9379 [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.swiecki@gmail.com97c77332015-02-14 23:06:58 +00008 * Copyright 2010-2015 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
24#include "common.h"
25#include "report.h"
26
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/types.h>
31#include <sys/stat.h>
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000032
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000033#include "log.h"
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000034#include "util.h"
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000035
36static int reportFD = -1;
37
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030038#if defined(_HF_ARCH_LINUX)
39static 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 ");
Jagger3abc5602016-02-04 00:53:43 +010049 if (hfuzz->dynFileMethod & _HF_DYNFILE_BTS_BLOCK)
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030050 dprintf(reportFD, "BLOCK_COUNT ");
Jagger3abc5602016-02-04 00:53:43 +010051 if (hfuzz->dynFileMethod & _HF_DYNFILE_BTS_EDGE)
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030052 dprintf(reportFD, "EDGE_COUNT ");
53 if (hfuzz->dynFileMethod & _HF_DYNFILE_CUSTOM)
54 dprintf(reportFD, "CUSTOM ");
Anestis Bechtsoudisf9f4a852015-08-18 14:30:02 +030055
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030056 dprintf(reportFD, "\n");
57 }
58}
59#endif
60
61static 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
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000070void report_Report(honggfuzz_t * hfuzz, char *s)
71{
Robert Swiecki5795fd62016-10-18 18:18:01 +020072 if (s == NULL || s[0] == '\0') {
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000073 return;
74 }
75
Robert Swiecki216fef62016-10-20 18:32:58 +020076 MX_SCOPED_LOCK(&hfuzz->report_mutex);
77
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000078 if (reportFD == -1) {
Jagger55e3bee2015-09-10 00:07:23 +020079 char reportFName[PATH_MAX];
80 if (hfuzz->reportFile == NULL) {
81 snprintf(reportFName, sizeof(reportFName), "%s/%s", hfuzz->workDir, _HF_REPORT_FILE);
82 } else {
83 snprintf(reportFName, sizeof(reportFName), "%s", hfuzz->reportFile);
84 }
85
Jagger5a3c4c32016-04-16 19:27:47 +020086 reportFD = open(reportFName, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644);
Jagger55e3bee2015-09-10 00:07:23 +020087 if (reportFD == -1) {
Robert Swieckic8c32db2015-10-09 18:06:22 +020088 PLOG_F("Couldn't open('%s') for writing", reportFName);
Jagger55e3bee2015-09-10 00:07:23 +020089 }
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000090 }
91
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000092 char localtmstr[PATH_MAX];
Robert Swiecki81c6a0d2015-09-08 15:43:20 +020093 util_getLocalTime("%F.%H:%M:%S", localtmstr, sizeof(localtmstr), time(NULL));
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000094
95 dprintf(reportFD,
96 "=====================================================================\n"
97 "TIME: %s\n"
98 "=====================================================================\n"
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030099 "FUZZER ARGS:\n"
100 " flipRate : %lf\n"
101 " externalCmd : %s\n"
102 " fuzzStdin : %s\n"
103 " timeout : %ld (sec)\n"
104 " ignoreAddr : %p\n"
Jagger921bf562015-09-08 22:05:47 +0200105 " memoryLimit : %" PRIu64 " (MiB)\n"
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300106 " targetPid : %d\n"
Anestis Bechtsoudis7c88d7a2016-02-09 17:55:38 +0200107 " targetCmd : %s\n"
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300108 " wordlistFile : %s\n",
109 localtmstr,
Robert Swieckia96d78d2016-03-14 16:50:50 +0100110 hfuzz->origFlipRate,
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300111 hfuzz->externalCommand == NULL ? "NULL" : hfuzz->externalCommand,
112 hfuzz->fuzzStdin ? "TRUE" : "FALSE",
113 hfuzz->tmOut,
Jagger247c3b42016-03-21 23:24:05 +0100114 hfuzz->linux.ignoreAddr,
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300115 hfuzz->asLimit,
Jagger247c3b42016-03-21 23:24:05 +0100116 hfuzz->linux.pid,
117 hfuzz->linux.pidCmd, hfuzz->dictionaryFile == NULL ? "NULL" : hfuzz->dictionaryFile);
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300118
119#if defined(_HF_ARCH_LINUX)
120 report_printdynFileMethod(hfuzz);
121#endif
122
123 report_printTargetCmd(hfuzz);
124
125 dprintf(reportFD,
Jaggerd628a702015-08-23 12:59:37 +0200126 "%s" "=====================================================================\n", s);
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +0000127}