blob: fe08c83e2d31644038e5dee3b9a601f99800da66 [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>
28#include <stdio.h>
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000029#include <sys/types.h>
30#include <sys/stat.h>
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000031
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000032#include "log.h"
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000033#include "util.h"
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000034
35static int reportFD = -1;
36
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030037#if defined(_HF_ARCH_LINUX)
38static void report_printdynFileMethod(honggfuzz_t * hfuzz)
39{
40 dprintf(reportFD, " dynFileMethod: ");
41 if (hfuzz->dynFileMethod == 0)
42 dprintf(reportFD, "NONE\n");
43 else {
44 if (hfuzz->dynFileMethod & _HF_DYNFILE_INSTR_COUNT)
45 dprintf(reportFD, "INSTR_COUNT ");
46 if (hfuzz->dynFileMethod & _HF_DYNFILE_BRANCH_COUNT)
47 dprintf(reportFD, "BRANCH_COUNT ");
48 if (hfuzz->dynFileMethod & _HF_DYNFILE_UNIQUE_BLOCK_COUNT)
49 dprintf(reportFD, "BLOCK_COUNT ");
50 if (hfuzz->dynFileMethod & _HF_DYNFILE_UNIQUE_EDGE_COUNT)
51 dprintf(reportFD, "EDGE_COUNT ");
52 if (hfuzz->dynFileMethod & _HF_DYNFILE_CUSTOM)
53 dprintf(reportFD, "CUSTOM ");
Anestis Bechtsoudisf9f4a852015-08-18 14:30:02 +030054
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030055 dprintf(reportFD, "\n");
56 }
57}
58#endif
59
60static void report_printTargetCmd(honggfuzz_t * hfuzz)
61{
62 dprintf(reportFD, " fuzzTarget : ");
63 for (int x = 0; hfuzz->cmdline[x]; x++) {
64 dprintf(reportFD, "%s ", hfuzz->cmdline[x]);
65 }
66 dprintf(reportFD, "\n");
67}
68
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +000069void report_Report(honggfuzz_t * hfuzz, char *s)
70{
71 if (s[0] == '\0') {
72 return;
73 }
74
75 if (reportFD == -1) {
76 reportFD = open(hfuzz->reportFile, O_WRONLY | O_CREAT | O_APPEND, 0644);
77 }
78 if (reportFD == -1) {
79 LOGMSG_P(l_FATAL, "Couldn't open('%s') for writing", hfuzz->reportFile);
80 }
81
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000082 char localtmstr[PATH_MAX];
Robert Swiecki81c6a0d2015-09-08 15:43:20 +020083 util_getLocalTime("%F.%H:%M:%S", localtmstr, sizeof(localtmstr), time(NULL));
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +000084
85 dprintf(reportFD,
86 "=====================================================================\n"
87 "TIME: %s\n"
88 "=====================================================================\n"
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030089 "FUZZER ARGS:\n"
90 " flipRate : %lf\n"
91 " externalCmd : %s\n"
92 " fuzzStdin : %s\n"
93 " timeout : %ld (sec)\n"
94 " ignoreAddr : %p\n"
Anestis Bechtsoudis46a69782015-09-08 22:26:53 +030095 " memoryLimit : %llu (MiB)\n"
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +030096 " targetPid : %d\n"
97 " wordlistFile : %s\n",
98 localtmstr,
99 hfuzz->flipRate,
100 hfuzz->externalCommand == NULL ? "NULL" : hfuzz->externalCommand,
101 hfuzz->fuzzStdin ? "TRUE" : "FALSE",
102 hfuzz->tmOut,
103 hfuzz->ignoreAddr,
104 hfuzz->asLimit,
Jaggerd628a702015-08-23 12:59:37 +0200105 hfuzz->pid, hfuzz->dictionaryFile == NULL ? "NULL" : hfuzz->dictionaryFile);
Anestis Bechtsoudisf5268a62015-08-07 16:48:46 +0300106
107#if defined(_HF_ARCH_LINUX)
108 report_printdynFileMethod(hfuzz);
109#endif
110
111 report_printTargetCmd(hfuzz);
112
113 dprintf(reportFD,
Jaggerd628a702015-08-23 12:59:37 +0200114 "%s" "=====================================================================\n", s);
robert.swiecki@gmail.com97c77332015-02-14 23:06:58 +0000115
116 return;
117}