blob: a8e61578746dd47ee89fd99681295890c21b183e [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
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000024#include "report.h"
25
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000026#include <fcntl.h>
Jagger921bf562015-09-08 22:05:47 +020027#include <inttypes.h>
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000028#include <stdio.h>
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000029#include <sys/stat.h>
Robert Swieckid0fa62c2017-09-28 18:11:05 +020030#include <sys/types.h>
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000031
Robert Swiecki10eeb0a2017-09-28 15:42:52 +020032#include "libcommon/common.h"
Robert Swiecki241a7412017-05-24 01:53:15 +020033#include "libcommon/log.h"
34#include "libcommon/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)
Robert Swieckid50ed422017-11-13 23:32:26 +010039static void report_printdynFileMethod(run_t* run) {
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030040 dprintf(reportFD, " dynFileMethod: ");
Robert Swiecki78633d12017-11-13 23:24:55 +010041 if (run->global->dynFileMethod == 0)
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030042 dprintf(reportFD, "NONE\n");
43 else {
Robert Swieckid50ed422017-11-13 23:32:26 +010044 if (run->global->dynFileMethod & _HF_DYNFILE_INSTR_COUNT) dprintf(reportFD, "INSTR_COUNT ");
Robert Swiecki78633d12017-11-13 23:24:55 +010045 if (run->global->dynFileMethod & _HF_DYNFILE_BRANCH_COUNT)
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030046 dprintf(reportFD, "BRANCH_COUNT ");
Robert Swieckid50ed422017-11-13 23:32:26 +010047 if (run->global->dynFileMethod & _HF_DYNFILE_BTS_EDGE) dprintf(reportFD, "BTS_EDGE_COUNT ");
Robert Swiecki78633d12017-11-13 23:24:55 +010048 if (run->global->dynFileMethod & _HF_DYNFILE_IPT_BLOCK)
Robert Swiecki6134ce02017-06-14 14:58:37 +020049 dprintf(reportFD, "IPT_BLOCK_COUNT ");
Anestis Bechtsoudisf9f4a852015-08-18 14:30:02 +030050
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030051 dprintf(reportFD, "\n");
52 }
53}
54#endif
55
Robert Swieckid50ed422017-11-13 23:32:26 +010056static void report_printTargetCmd(run_t* run) {
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030057 dprintf(reportFD, " fuzzTarget : ");
Robert Swiecki78633d12017-11-13 23:24:55 +010058 for (int x = 0; run->global->cmdline[x]; x++) {
59 dprintf(reportFD, "%s ", run->global->cmdline[x]);
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030060 }
61 dprintf(reportFD, "\n");
62}
63
Robert Swieckid50ed422017-11-13 23:32:26 +010064void report_Report(run_t* run) {
Robert Swieckid440cbb2017-11-14 00:47:11 +010065 if (run->report[0] == '\0') {
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000066 return;
67 }
68
Robert Swiecki78633d12017-11-13 23:24:55 +010069 MX_SCOPED_LOCK(&run->global->report_mutex);
Robert Swiecki216fef62016-10-20 18:32:58 +020070
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000071 if (reportFD == -1) {
Jagger55e3bee2015-09-10 00:07:23 +020072 char reportFName[PATH_MAX];
Robert Swiecki78633d12017-11-13 23:24:55 +010073 if (run->global->reportFile == NULL) {
Robert Swiecki82c707c2017-11-14 16:36:23 +010074 snprintf(reportFName, sizeof(reportFName), "%s/%s", run->global->io.workDir,
75 _HF_REPORT_FILE);
Jagger55e3bee2015-09-10 00:07:23 +020076 } else {
Robert Swiecki78633d12017-11-13 23:24:55 +010077 snprintf(reportFName, sizeof(reportFName), "%s", run->global->reportFile);
Jagger55e3bee2015-09-10 00:07:23 +020078 }
79
Jagger5a3c4c32016-04-16 19:27:47 +020080 reportFD = open(reportFName, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644);
Jagger55e3bee2015-09-10 00:07:23 +020081 if (reportFD == -1) {
Robert Swieckic8c32db2015-10-09 18:06:22 +020082 PLOG_F("Couldn't open('%s') for writing", reportFName);
Jagger55e3bee2015-09-10 00:07:23 +020083 }
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000084 }
85
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000086 char localtmstr[PATH_MAX];
Robert Swiecki81c6a0d2015-09-08 15:43:20 +020087 util_getLocalTime("%F.%H:%M:%S", localtmstr, sizeof(localtmstr), time(NULL));
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000088
89 dprintf(reportFD,
Robert Swiecki4e595fb2017-10-11 17:26:51 +020090 "=====================================================================\n"
91 "TIME: %s\n"
92 "=====================================================================\n"
93 "FUZZER ARGS:\n"
Robert Swiecki10e93562017-11-04 00:57:47 +010094 " mutationsPerRun : %u\n"
95 " externalCmd : %s\n"
96 " fuzzStdin : %s\n"
97 " timeout : %ld (sec)\n"
98 " ignoreAddr : %p\n"
Robert Swiecki8954afd2017-11-14 18:14:22 +010099 " ASLimit : %" PRIu64
100 " (MiB)\n"
101 " RSSLimit : %" PRIu64
102 " (MiB)\n"
103 " DATALimit : %" PRIu64
Robert Swieckid50ed422017-11-13 23:32:26 +0100104 " (MiB)\n"
Robert Swiecki10e93562017-11-04 00:57:47 +0100105 " targetPid : %d\n"
106 " targetCmd : %s\n"
107 " wordlistFile : %s\n",
Robert Swiecki78633d12017-11-13 23:24:55 +0100108 localtmstr, run->global->mutationsPerRun,
109 run->global->externalCommand == NULL ? "NULL" : run->global->externalCommand,
110 run->global->fuzzStdin ? "TRUE" : "FALSE", run->global->tmOut,
Robert Swiecki8954afd2017-11-14 18:14:22 +0100111 run->global->linux.ignoreAddr, run->global->asLimit, run->global->rssLimit,
112 run->global->dataLimit, run->global->linux.pid, run->global->linux.pidCmd,
Robert Swiecki78633d12017-11-13 23:24:55 +0100113 run->global->dictionaryFile == NULL ? "NULL" : run->global->dictionaryFile);
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300114
115#if defined(_HF_ARCH_LINUX)
Robert Swiecki78633d12017-11-13 23:24:55 +0100116 report_printdynFileMethod(run);
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300117#endif
118
Robert Swiecki78633d12017-11-13 23:24:55 +0100119 report_printTargetCmd(run);
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300120
121 dprintf(reportFD,
Robert Swiecki4e595fb2017-10-11 17:26:51 +0200122 "%s"
123 "=====================================================================\n",
Robert Swiecki78633d12017-11-13 23:24:55 +0100124 run->report);
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +0000125}