robert.swiecki@gmail.com | 97c7733 | 2015-02-14 23:06:58 +0000 | [diff] [blame] | 1 | /* |
robert.swiecki@gmail.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 2 | * |
robert.swiecki@gmail.com | 97c7733 | 2015-02-14 23:06:58 +0000 | [diff] [blame] | 3 | * honggfuzz - reporting |
| 4 | * ----------------------------------------- |
robert.swiecki@gmail.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 5 | * |
robert.swiecki@gmail.com | 97c7733 | 2015-02-14 23:06:58 +0000 | [diff] [blame] | 6 | * Author: Robert Swiecki <swiecki@google.com> |
robert.swiecki@gmail.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 7 | * |
robert.swiecki@gmail.com | 97c7733 | 2015-02-14 23:06:58 +0000 | [diff] [blame] | 8 | * Copyright 2010-2015 by Google Inc. All Rights Reserved. |
robert.swiecki@gmail.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 9 | * |
| 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.com | 97c7733 | 2015-02-14 23:06:58 +0000 | [diff] [blame] | 12 | * a copy of the License at |
robert.swiecki@gmail.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 13 | * |
robert.swiecki@gmail.com | 97c7733 | 2015-02-14 23:06:58 +0000 | [diff] [blame] | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
robert.swiecki@gmail.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 15 | * |
robert.swiecki@gmail.com | 97c7733 | 2015-02-14 23:06:58 +0000 | [diff] [blame] | 16 | * 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.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 21 | * |
robert.swiecki@gmail.com | 97c7733 | 2015-02-14 23:06:58 +0000 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | #include "common.h" |
| 25 | #include "report.h" |
| 26 | |
robert.swiecki@gmail.com | 90e9911 | 2015-02-15 02:05:14 +0000 | [diff] [blame] | 27 | #include <fcntl.h> |
Jagger | 921bf56 | 2015-09-08 22:05:47 +0200 | [diff] [blame] | 28 | #include <inttypes.h> |
robert.swiecki@gmail.com | 90e9911 | 2015-02-15 02:05:14 +0000 | [diff] [blame] | 29 | #include <stdio.h> |
robert.swiecki@gmail.com | 97c7733 | 2015-02-14 23:06:58 +0000 | [diff] [blame] | 30 | #include <sys/types.h> |
| 31 | #include <sys/stat.h> |
robert.swiecki@gmail.com | 97c7733 | 2015-02-14 23:06:58 +0000 | [diff] [blame] | 32 | |
robert.swiecki@gmail.com | 97c7733 | 2015-02-14 23:06:58 +0000 | [diff] [blame] | 33 | #include "log.h" |
robert.swiecki@gmail.com | 90e9911 | 2015-02-15 02:05:14 +0000 | [diff] [blame] | 34 | #include "util.h" |
robert.swiecki@gmail.com | 97c7733 | 2015-02-14 23:06:58 +0000 | [diff] [blame] | 35 | |
| 36 | static int reportFD = -1; |
| 37 | |
Anestis Bechtsoudis | f5268a6 | 2015-08-07 16:48:46 +0300 | [diff] [blame] | 38 | #if defined(_HF_ARCH_LINUX) |
| 39 | static 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 "); |
Jagger | 3abc560 | 2016-02-04 00:53:43 +0100 | [diff] [blame] | 49 | if (hfuzz->dynFileMethod & _HF_DYNFILE_BTS_BLOCK) |
Anestis Bechtsoudis | f5268a6 | 2015-08-07 16:48:46 +0300 | [diff] [blame] | 50 | dprintf(reportFD, "BLOCK_COUNT "); |
Jagger | 3abc560 | 2016-02-04 00:53:43 +0100 | [diff] [blame] | 51 | if (hfuzz->dynFileMethod & _HF_DYNFILE_BTS_EDGE) |
Anestis Bechtsoudis | f5268a6 | 2015-08-07 16:48:46 +0300 | [diff] [blame] | 52 | dprintf(reportFD, "EDGE_COUNT "); |
| 53 | if (hfuzz->dynFileMethod & _HF_DYNFILE_CUSTOM) |
| 54 | dprintf(reportFD, "CUSTOM "); |
Anestis Bechtsoudis | f9f4a85 | 2015-08-18 14:30:02 +0300 | [diff] [blame] | 55 | |
Anestis Bechtsoudis | f5268a6 | 2015-08-07 16:48:46 +0300 | [diff] [blame] | 56 | dprintf(reportFD, "\n"); |
| 57 | } |
| 58 | } |
| 59 | #endif |
| 60 | |
| 61 | static 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.com | 97c7733 | 2015-02-14 23:06:58 +0000 | [diff] [blame] | 70 | void report_Report(honggfuzz_t * hfuzz, char *s) |
| 71 | { |
| 72 | if (s[0] == '\0') { |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | if (reportFD == -1) { |
Jagger | 55e3bee | 2015-09-10 00:07:23 +0200 | [diff] [blame] | 77 | 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 | |
Jagger | 5a3c4c3 | 2016-04-16 19:27:47 +0200 | [diff] [blame] | 84 | reportFD = open(reportFName, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644); |
Jagger | 55e3bee | 2015-09-10 00:07:23 +0200 | [diff] [blame] | 85 | if (reportFD == -1) { |
Robert Swiecki | c8c32db | 2015-10-09 18:06:22 +0200 | [diff] [blame] | 86 | PLOG_F("Couldn't open('%s') for writing", reportFName); |
Jagger | 55e3bee | 2015-09-10 00:07:23 +0200 | [diff] [blame] | 87 | } |
robert.swiecki@gmail.com | 97c7733 | 2015-02-14 23:06:58 +0000 | [diff] [blame] | 88 | } |
| 89 | |
robert.swiecki@gmail.com | 90e9911 | 2015-02-15 02:05:14 +0000 | [diff] [blame] | 90 | char localtmstr[PATH_MAX]; |
Robert Swiecki | 81c6a0d | 2015-09-08 15:43:20 +0200 | [diff] [blame] | 91 | util_getLocalTime("%F.%H:%M:%S", localtmstr, sizeof(localtmstr), time(NULL)); |
robert.swiecki@gmail.com | 90e9911 | 2015-02-15 02:05:14 +0000 | [diff] [blame] | 92 | |
| 93 | dprintf(reportFD, |
| 94 | "=====================================================================\n" |
| 95 | "TIME: %s\n" |
| 96 | "=====================================================================\n" |
Anestis Bechtsoudis | f5268a6 | 2015-08-07 16:48:46 +0300 | [diff] [blame] | 97 | "FUZZER ARGS:\n" |
| 98 | " flipRate : %lf\n" |
| 99 | " externalCmd : %s\n" |
| 100 | " fuzzStdin : %s\n" |
| 101 | " timeout : %ld (sec)\n" |
| 102 | " ignoreAddr : %p\n" |
Jagger | 921bf56 | 2015-09-08 22:05:47 +0200 | [diff] [blame] | 103 | " memoryLimit : %" PRIu64 " (MiB)\n" |
Anestis Bechtsoudis | f5268a6 | 2015-08-07 16:48:46 +0300 | [diff] [blame] | 104 | " targetPid : %d\n" |
Anestis Bechtsoudis | 7c88d7a | 2016-02-09 17:55:38 +0200 | [diff] [blame] | 105 | " targetCmd : %s\n" |
Anestis Bechtsoudis | f5268a6 | 2015-08-07 16:48:46 +0300 | [diff] [blame] | 106 | " wordlistFile : %s\n", |
| 107 | localtmstr, |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 108 | hfuzz->origFlipRate, |
Anestis Bechtsoudis | f5268a6 | 2015-08-07 16:48:46 +0300 | [diff] [blame] | 109 | hfuzz->externalCommand == NULL ? "NULL" : hfuzz->externalCommand, |
| 110 | hfuzz->fuzzStdin ? "TRUE" : "FALSE", |
| 111 | hfuzz->tmOut, |
Jagger | 247c3b4 | 2016-03-21 23:24:05 +0100 | [diff] [blame] | 112 | hfuzz->linux.ignoreAddr, |
Anestis Bechtsoudis | f5268a6 | 2015-08-07 16:48:46 +0300 | [diff] [blame] | 113 | hfuzz->asLimit, |
Jagger | 247c3b4 | 2016-03-21 23:24:05 +0100 | [diff] [blame] | 114 | hfuzz->linux.pid, |
| 115 | hfuzz->linux.pidCmd, hfuzz->dictionaryFile == NULL ? "NULL" : hfuzz->dictionaryFile); |
Anestis Bechtsoudis | f5268a6 | 2015-08-07 16:48:46 +0300 | [diff] [blame] | 116 | |
| 117 | #if defined(_HF_ARCH_LINUX) |
| 118 | report_printdynFileMethod(hfuzz); |
| 119 | #endif |
| 120 | |
| 121 | report_printTargetCmd(hfuzz); |
| 122 | |
| 123 | dprintf(reportFD, |
Jagger | d628a70 | 2015-08-23 12:59:37 +0200 | [diff] [blame] | 124 | "%s" "=====================================================================\n", s); |
robert.swiecki@gmail.com | 97c7733 | 2015-02-14 23:06:58 +0000 | [diff] [blame] | 125 | } |