1 /* 2 * 3 * honggfuzz - reporting 4 * ----------------------------------------- 5 * 6 * Author: Robert Swiecki <swiecki (at) google.com> 7 * 8 * Copyright 2010-2015 by Google Inc. All Rights Reserved. 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 12 * a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 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. 21 * 22 */ 23 24 #include "report.h" 25 26 #include <fcntl.h> 27 #include <inttypes.h> 28 #include <stdio.h> 29 #include <sys/stat.h> 30 #include <sys/types.h> 31 32 #include "libcommon/common.h" 33 #include "libcommon/log.h" 34 #include "libcommon/util.h" 35 36 static int reportFD = -1; 37 38 #if defined(_HF_ARCH_LINUX) 39 static void report_printdynFileMethod(run_t* run) { 40 dprintf(reportFD, " dynFileMethod: "); 41 if (run->global->dynFileMethod == 0) 42 dprintf(reportFD, "NONE\n"); 43 else { 44 if (run->global->dynFileMethod & _HF_DYNFILE_INSTR_COUNT) dprintf(reportFD, "INSTR_COUNT "); 45 if (run->global->dynFileMethod & _HF_DYNFILE_BRANCH_COUNT) 46 dprintf(reportFD, "BRANCH_COUNT "); 47 if (run->global->dynFileMethod & _HF_DYNFILE_BTS_EDGE) dprintf(reportFD, "BTS_EDGE_COUNT "); 48 if (run->global->dynFileMethod & _HF_DYNFILE_IPT_BLOCK) 49 dprintf(reportFD, "IPT_BLOCK_COUNT "); 50 51 dprintf(reportFD, "\n"); 52 } 53 } 54 #endif 55 56 static void report_printTargetCmd(run_t* run) { 57 dprintf(reportFD, " fuzzTarget : "); 58 for (int x = 0; run->global->exe.cmdline[x]; x++) { 59 dprintf(reportFD, "%s ", run->global->exe.cmdline[x]); 60 } 61 dprintf(reportFD, "\n"); 62 } 63 64 void report_Report(run_t* run) { 65 if (run->report[0] == '\0') { 66 return; 67 } 68 69 MX_SCOPED_LOCK(&run->global->report_mutex); 70 71 if (reportFD == -1) { 72 char reportFName[PATH_MAX]; 73 if (run->global->reportFile == NULL) { 74 snprintf(reportFName, sizeof(reportFName), "%s/%s", run->global->io.workDir, 75 _HF_REPORT_FILE); 76 } else { 77 snprintf(reportFName, sizeof(reportFName), "%s", run->global->reportFile); 78 } 79 80 reportFD = open(reportFName, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0644); 81 if (reportFD == -1) { 82 PLOG_F("Couldn't open('%s') for writing", reportFName); 83 } 84 } 85 86 char localtmstr[PATH_MAX]; 87 util_getLocalTime("%F.%H:%M:%S", localtmstr, sizeof(localtmstr), time(NULL)); 88 89 dprintf(reportFD, 90 "=====================================================================\n" 91 "TIME: %s\n" 92 "=====================================================================\n" 93 "FUZZER ARGS:\n" 94 " mutationsPerRun : %u\n" 95 " externalCmd : %s\n" 96 " fuzzStdin : %s\n" 97 " timeout : %ld (sec)\n" 98 " ignoreAddr : %p\n" 99 " ASLimit : %" PRIu64 100 " (MiB)\n" 101 " RSSLimit : %" PRIu64 102 " (MiB)\n" 103 " DATALimit : %" PRIu64 104 " (MiB)\n" 105 " targetPid : %d\n" 106 " targetCmd : %s\n" 107 " wordlistFile : %s\n", 108 localtmstr, run->global->mutationsPerRun, 109 run->global->exe.externalCommand == NULL ? "NULL" : run->global->exe.externalCommand, 110 run->global->exe.fuzzStdin ? "TRUE" : "FALSE", run->global->timing.tmOut, 111 run->global->linux.ignoreAddr, run->global->exe.asLimit, run->global->exe.rssLimit, 112 run->global->exe.dataLimit, run->global->linux.pid, run->global->linux.pidCmd, 113 run->global->dictionaryFile == NULL ? "NULL" : run->global->dictionaryFile); 114 115 #if defined(_HF_ARCH_LINUX) 116 report_printdynFileMethod(run); 117 #endif 118 119 report_printTargetCmd(run); 120 121 dprintf(reportFD, 122 "%s" 123 "=====================================================================\n", 124 run->report); 125 } 126