blob: e486b1fd7b08c3f8da9f2303a057b63a32936365 [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{
72 if (s[0] == '\0') {
73 return;
74 }
75
76 if (reportFD == -1) {
Jagger55e3bee2015-09-10 00:07:23 +020077 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
Jagger5a3c4c32016-04-16 19:27:47 +020084 reportFD = open(reportFName, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644);
Jagger55e3bee2015-09-10 00:07:23 +020085 if (reportFD == -1) {
Robert Swieckic8c32db2015-10-09 18:06:22 +020086 PLOG_F("Couldn't open('%s') for writing", reportFName);
Jagger55e3bee2015-09-10 00:07:23 +020087 }
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000088 }
89
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000090 char localtmstr[PATH_MAX];
Robert Swiecki81c6a0d2015-09-08 15:43:20 +020091 util_getLocalTime("%F.%H:%M:%S", localtmstr, sizeof(localtmstr), time(NULL));
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000092
93 dprintf(reportFD,
94 "=====================================================================\n"
95 "TIME: %s\n"
96 "=====================================================================\n"
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030097 "FUZZER ARGS:\n"
98 " flipRate : %lf\n"
99 " externalCmd : %s\n"
100 " fuzzStdin : %s\n"
101 " timeout : %ld (sec)\n"
102 " ignoreAddr : %p\n"
Jagger921bf562015-09-08 22:05:47 +0200103 " memoryLimit : %" PRIu64 " (MiB)\n"
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300104 " targetPid : %d\n"
Anestis Bechtsoudis7c88d7a2016-02-09 17:55:38 +0200105 " targetCmd : %s\n"
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300106 " wordlistFile : %s\n",
107 localtmstr,
Robert Swieckia96d78d2016-03-14 16:50:50 +0100108 hfuzz->origFlipRate,
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300109 hfuzz->externalCommand == NULL ? "NULL" : hfuzz->externalCommand,
110 hfuzz->fuzzStdin ? "TRUE" : "FALSE",
111 hfuzz->tmOut,
Jagger247c3b42016-03-21 23:24:05 +0100112 hfuzz->linux.ignoreAddr,
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300113 hfuzz->asLimit,
Jagger247c3b42016-03-21 23:24:05 +0100114 hfuzz->linux.pid,
115 hfuzz->linux.pidCmd, hfuzz->dictionaryFile == NULL ? "NULL" : hfuzz->dictionaryFile);
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300116
117#if defined(_HF_ARCH_LINUX)
118 report_printdynFileMethod(hfuzz);
119#endif
120
121 report_printTargetCmd(hfuzz);
122
123 dprintf(reportFD,
Jaggerd628a702015-08-23 12:59:37 +0200124 "%s" "=====================================================================\n", s);
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +0000125}