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 "); |
| 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 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 | |
| 84 | reportFD = open(reportFName, O_WRONLY | O_CREAT | O_APPEND, 0644); |
| 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" |
| 105 | " wordlistFile : %s\n", |
| 106 | localtmstr, |
| 107 | hfuzz->flipRate, |
| 108 | hfuzz->externalCommand == NULL ? "NULL" : hfuzz->externalCommand, |
| 109 | hfuzz->fuzzStdin ? "TRUE" : "FALSE", |
| 110 | hfuzz->tmOut, |
| 111 | hfuzz->ignoreAddr, |
| 112 | hfuzz->asLimit, |
Jagger | d628a70 | 2015-08-23 12:59:37 +0200 | [diff] [blame] | 113 | hfuzz->pid, hfuzz->dictionaryFile == NULL ? "NULL" : hfuzz->dictionaryFile); |
Anestis Bechtsoudis | f5268a6 | 2015-08-07 16:48:46 +0300 | [diff] [blame] | 114 | |
| 115 | #if defined(_HF_ARCH_LINUX) |
| 116 | report_printdynFileMethod(hfuzz); |
| 117 | #endif |
| 118 | |
| 119 | report_printTargetCmd(hfuzz); |
| 120 | |
| 121 | dprintf(reportFD, |
Jagger | d628a70 | 2015-08-23 12:59:37 +0200 | [diff] [blame] | 122 | "%s" "=====================================================================\n", s); |
robert.swiecki@gmail.com | 97c7733 | 2015-02-14 23:06:58 +0000 | [diff] [blame] | 123 | |
| 124 | return; |
| 125 | } |