blob: e3bade1e87c1d6dff9a3c1ab828f3b6ad401c2ea [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 ");
49 if (hfuzz->dynFileMethod & _HF_DYNFILE_UNIQUE_BLOCK_COUNT)
50 dprintf(reportFD, "BLOCK_COUNT ");
51 if (hfuzz->dynFileMethod & _HF_DYNFILE_UNIQUE_EDGE_COUNT)
52 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) {
77 reportFD = open(hfuzz->reportFile, O_WRONLY | O_CREAT | O_APPEND, 0644);
78 }
79 if (reportFD == -1) {
80 LOGMSG_P(l_FATAL, "Couldn't open('%s') for writing", hfuzz->reportFile);
81 }
82
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000083 char localtmstr[PATH_MAX];
Robert Swiecki81c6a0d2015-09-08 15:43:20 +020084 util_getLocalTime("%F.%H:%M:%S", localtmstr, sizeof(localtmstr), time(NULL));
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000085
86 dprintf(reportFD,
87 "=====================================================================\n"
88 "TIME: %s\n"
89 "=====================================================================\n"
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030090 "FUZZER ARGS:\n"
91 " flipRate : %lf\n"
92 " externalCmd : %s\n"
93 " fuzzStdin : %s\n"
94 " timeout : %ld (sec)\n"
95 " ignoreAddr : %p\n"
Jagger921bf562015-09-08 22:05:47 +020096 " memoryLimit : %" PRIu64 " (MiB)\n"
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030097 " targetPid : %d\n"
98 " wordlistFile : %s\n",
99 localtmstr,
100 hfuzz->flipRate,
101 hfuzz->externalCommand == NULL ? "NULL" : hfuzz->externalCommand,
102 hfuzz->fuzzStdin ? "TRUE" : "FALSE",
103 hfuzz->tmOut,
104 hfuzz->ignoreAddr,
105 hfuzz->asLimit,
Jaggerd628a702015-08-23 12:59:37 +0200106 hfuzz->pid, hfuzz->dictionaryFile == NULL ? "NULL" : hfuzz->dictionaryFile);
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300107
108#if defined(_HF_ARCH_LINUX)
109 report_printdynFileMethod(hfuzz);
110#endif
111
112 report_printTargetCmd(hfuzz);
113
114 dprintf(reportFD,
Jaggerd628a702015-08-23 12:59:37 +0200115 "%s" "=====================================================================\n", s);
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +0000116
117 return;
118}