blob: d50b061f9bf10b7eb39c44f2ac551201b58df7f2 [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 Swiecki46288f72018-02-27 17:28:47 +01008 * Copyright 2010-2018 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 Swiecki246af3e2018-01-05 14:56:32 +010032#include "libhfcommon/common.h"
33#include "libhfcommon/log.h"
34#include "libhfcommon/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 Swieckia5b918a2018-03-07 23:59:53 +010041 if (run->global->feedback.dynFileMethod == 0)
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030042 dprintf(reportFD, "NONE\n");
43 else {
Robert Swieckia5b918a2018-03-07 23:59:53 +010044 if (run->global->feedback.dynFileMethod & _HF_DYNFILE_INSTR_COUNT)
45 dprintf(reportFD, "INSTR_COUNT ");
46 if (run->global->feedback.dynFileMethod & _HF_DYNFILE_BRANCH_COUNT)
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030047 dprintf(reportFD, "BRANCH_COUNT ");
Robert Swieckia5b918a2018-03-07 23:59:53 +010048 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)
Robert Swiecki6134ce02017-06-14 14:58:37 +020051 dprintf(reportFD, "IPT_BLOCK_COUNT ");
Anestis Bechtsoudisf9f4a852015-08-18 14:30:02 +030052
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030053 dprintf(reportFD, "\n");
54 }
55}
56#endif
57
Robert Swieckid50ed422017-11-13 23:32:26 +010058static void report_printTargetCmd(run_t* run) {
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030059 dprintf(reportFD, " fuzzTarget : ");
Robert Swiecki97d0cee2017-12-18 00:17:50 +010060 for (int x = 0; run->global->exe.cmdline[x]; x++) {
61 dprintf(reportFD, "%s ", run->global->exe.cmdline[x]);
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030062 }
63 dprintf(reportFD, "\n");
64}
65
Robert Swieckid50ed422017-11-13 23:32:26 +010066void report_Report(run_t* run) {
Robert Swieckid440cbb2017-11-14 00:47:11 +010067 if (run->report[0] == '\0') {
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000068 return;
69 }
70
Robert Swieckia5b918a2018-03-07 23:59:53 +010071 MX_SCOPED_LOCK(&run->global->cfg.report_mutex);
Robert Swiecki216fef62016-10-20 18:32:58 +020072
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000073 if (reportFD == -1) {
Jagger55e3bee2015-09-10 00:07:23 +020074 char reportFName[PATH_MAX];
Robert Swieckia5b918a2018-03-07 23:59:53 +010075 if (run->global->cfg.reportFile == NULL) {
Robert Swiecki82c707c2017-11-14 16:36:23 +010076 snprintf(reportFName, sizeof(reportFName), "%s/%s", run->global->io.workDir,
77 _HF_REPORT_FILE);
Jagger55e3bee2015-09-10 00:07:23 +020078 } else {
Robert Swieckia5b918a2018-03-07 23:59:53 +010079 snprintf(reportFName, sizeof(reportFName), "%s", run->global->cfg.reportFile);
Jagger55e3bee2015-09-10 00:07:23 +020080 }
81
Jagger5a3c4c32016-04-16 19:27:47 +020082 reportFD = open(reportFName, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644);
Jagger55e3bee2015-09-10 00:07:23 +020083 if (reportFD == -1) {
Robert Swieckic8c32db2015-10-09 18:06:22 +020084 PLOG_F("Couldn't open('%s') for writing", reportFName);
Jagger55e3bee2015-09-10 00:07:23 +020085 }
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000086 }
87
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000088 char localtmstr[PATH_MAX];
Robert Swiecki81c6a0d2015-09-08 15:43:20 +020089 util_getLocalTime("%F.%H:%M:%S", localtmstr, sizeof(localtmstr), time(NULL));
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000090
91 dprintf(reportFD,
Robert Swiecki4e595fb2017-10-11 17:26:51 +020092 "=====================================================================\n"
93 "TIME: %s\n"
94 "=====================================================================\n"
95 "FUZZER ARGS:\n"
Robert Swiecki10e93562017-11-04 00:57:47 +010096 " mutationsPerRun : %u\n"
97 " externalCmd : %s\n"
98 " fuzzStdin : %s\n"
99 " timeout : %ld (sec)\n"
Kamil Rytarowskibdfe2a72018-08-18 12:28:29 +0200100#if defined(_HF_ARCH_LINUX) || defined(_HF_ARCH_NETBSD)
Robert Swiecki10e93562017-11-04 00:57:47 +0100101 " ignoreAddr : %p\n"
Kamil Rytarowskib2d550a2018-08-10 14:43:56 +0200102#endif
Robert Swiecki98e23372019-01-30 11:50:18 +0100103 " ASLimit : %" PRIu64 " (MiB)\n"
104 " RSSLimit : %" PRIu64 " (MiB)\n"
105 " DATALimit : %" PRIu64 " (MiB)\n"
Robert Swiecki10e93562017-11-04 00:57:47 +0100106 " wordlistFile : %s\n",
Robert Swiecki04dcac32018-03-02 03:05:26 +0100107 localtmstr, run->global->mutate.mutationsPerRun,
Robert Swiecki97d0cee2017-12-18 00:17:50 +0100108 run->global->exe.externalCommand == NULL ? "NULL" : run->global->exe.externalCommand,
Robert Swiecki371e1292017-12-18 01:10:33 +0100109 run->global->exe.fuzzStdin ? "TRUE" : "FALSE", run->global->timing.tmOut,
Kamil Rytarowskib2d550a2018-08-10 14:43:56 +0200110#if defined(_HF_ARCH_LINUX)
111 run->global->linux.ignoreAddr,
Kamil Rytarowskibdfe2a72018-08-18 12:28:29 +0200112#elif defined(_HF_ARCH_NETBSD)
113 run->global->netbsd.ignoreAddr,
Kamil Rytarowskib2d550a2018-08-10 14:43:56 +0200114#endif
115 run->global->exe.asLimit, run->global->exe.rssLimit, run->global->exe.dataLimit,
Robert Swiecki04dcac32018-03-02 03:05:26 +0100116 run->global->mutate.dictionaryFile == NULL ? "NULL" : run->global->mutate.dictionaryFile);
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300117
118#if defined(_HF_ARCH_LINUX)
Robert Swiecki78633d12017-11-13 23:24:55 +0100119 report_printdynFileMethod(run);
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300120#endif
121
Robert Swiecki78633d12017-11-13 23:24:55 +0100122 report_printTargetCmd(run);
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300123
124 dprintf(reportFD,
Robert Swiecki4e595fb2017-10-11 17:26:51 +0200125 "%s"
126 "=====================================================================\n",
Robert Swiecki78633d12017-11-13 23:24:55 +0100127 run->report);
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +0000128}