Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 1 | /* |
| 2 | |
| 3 | honggfuzz - cmdline parsing |
| 4 | |
| 5 | ----------------------------------------- |
| 6 | |
| 7 | Copyright 2014 Google Inc. All Rights Reserved. |
| 8 | |
| 9 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | you may not use this file except in compliance with the License. |
| 11 | You may obtain a copy of the License at |
| 12 | |
| 13 | http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | |
| 15 | Unless required by applicable law or agreed to in writing, software |
| 16 | distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | See the License for the specific language governing permissions and |
| 19 | limitations under the License. |
| 20 | |
| 21 | */ |
| 22 | |
| 23 | #include "cmdline.h" |
| 24 | |
| 25 | #include <ctype.h> |
| 26 | #include <errno.h> |
| 27 | #include <getopt.h> |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 28 | #include <inttypes.h> |
| 29 | #include <limits.h> |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 30 | #include <stdlib.h> |
| 31 | #include <stdio.h> |
| 32 | #include <string.h> |
Robert Swiecki | 3bfc33c | 2016-03-14 18:12:41 +0100 | [diff] [blame] | 33 | #include <sys/queue.h> |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 34 | #include <unistd.h> |
| 35 | |
| 36 | #include "common.h" |
| 37 | #include "log.h" |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 38 | #include "files.h" |
Robert Swiecki | 72d2bef | 2016-01-19 14:39:26 +0100 | [diff] [blame] | 39 | #include "util.h" |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 40 | |
| 41 | struct custom_option { |
| 42 | struct option opt; |
| 43 | const char *descr; |
| 44 | }; |
| 45 | |
| 46 | static bool checkFor_FILE_PLACEHOLDER(char **args) |
| 47 | { |
| 48 | for (int x = 0; args[x]; x++) { |
| 49 | if (strstr(args[x], _HF_FILE_PLACEHOLDER)) |
| 50 | return true; |
| 51 | } |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | static const char *cmdlineYesNo(bool yes) |
| 56 | { |
| 57 | return (yes ? "true" : "false"); |
| 58 | } |
| 59 | |
| 60 | static void cmdlineHelp(const char *pname, struct custom_option *opts) |
| 61 | { |
| 62 | LOG_HELP_BOLD("Usage: %s [options] -- path_to_command [args]", pname); |
| 63 | LOG_HELP_BOLD("Options:"); |
| 64 | for (int i = 0; opts[i].opt.name; i++) { |
Robert Swiecki | f3a5f6a | 2016-03-16 14:47:30 +0100 | [diff] [blame] | 65 | if (isprint(opts[i].opt.val) && opts[i].opt.val < 0x80) { |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 66 | LOG_HELP_BOLD(" --%s%s%c %s", opts[i].opt.name, |
| 67 | "|-", opts[i].opt.val, |
Robert Swiecki | bf063db | 2016-02-16 18:42:00 +0100 | [diff] [blame] | 68 | opts[i].opt.has_arg == required_argument ? "VALUE" : ""); |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 69 | } else { |
| 70 | LOG_HELP_BOLD(" --%s %s", opts[i].opt.name, |
Robert Swiecki | bf063db | 2016-02-16 18:42:00 +0100 | [diff] [blame] | 71 | opts[i].opt.has_arg == required_argument ? "VALUE" : ""); |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 72 | } |
| 73 | LOG_HELP("\t%s", opts[i].descr); |
| 74 | } |
Jagger | 3212737 | 2015-10-09 23:07:38 +0200 | [diff] [blame] | 75 | LOG_HELP_BOLD("\nExamples:"); |
| 76 | LOG_HELP(" Run the binary over a mutated file chosen from the directory"); |
| 77 | LOG_HELP_BOLD(" " PROG_NAME " -f input_dir -- /usr/bin/tiffinfo -D " _HF_FILE_PLACEHOLDER); |
| 78 | LOG_HELP(" As above, provide input over STDIN:"); |
Robert Swiecki | 72d2bef | 2016-01-19 14:39:26 +0100 | [diff] [blame] | 79 | LOG_HELP_BOLD(" " PROG_NAME " -f input_dir -s -- /usr/bin/djpeg"); |
Jagger | ba92b4b | 2016-03-16 02:24:17 +0100 | [diff] [blame] | 80 | LOG_HELP(" Use SANCOV to maximize code coverage:"); |
| 81 | LOG_HELP_BOLD(" " PROG_NAME " -f input_dir -C -- /usr/bin/tiffinfo -D " _HF_FILE_PLACEHOLDER); |
Jagger | e848cc7 | 2016-09-19 02:28:52 +0200 | [diff] [blame] | 82 | LOG_HELP(" Use compile-time instrumentation (libhfuzz/instrument.c):"); |
| 83 | LOG_HELP_BOLD(" " PROG_NAME " -f input_dir -z -- /usr/bin/tiffinfo -D " _HF_FILE_PLACEHOLDER); |
Robert Swiecki | a2d5be3 | 2016-10-11 22:52:42 +0200 | [diff] [blame] | 84 | LOG_HELP(" Use persistent mode (libhfuzz/persistent.c):"); |
Jagger | e848cc7 | 2016-09-19 02:28:52 +0200 | [diff] [blame] | 85 | LOG_HELP_BOLD(" " PROG_NAME " -f input_dir -P -- /usr/bin/tiffinfo_persistent"); |
Robert Swiecki | 43f0b28 | 2016-11-01 18:06:40 +0100 | [diff] [blame] | 86 | LOG_HELP |
| 87 | (" Use persistent mode (libhfuzz/persistent.c) and compile-time instrumentation (libhfuzz/instrument.c):"); |
Robert Swiecki | 1412949 | 2016-11-01 18:04:32 +0100 | [diff] [blame] | 88 | LOG_HELP_BOLD(" " PROG_NAME " -f input_dir -P -z -- /usr/bin/tiffinfo_persistent"); |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 89 | #if defined(_HF_ARCH_LINUX) |
Jagger | 3212737 | 2015-10-09 23:07:38 +0200 | [diff] [blame] | 90 | LOG_HELP(" Run the binary over a dynamic file, maximize total no. of instructions:"); |
Jagger | 72f258b | 2015-10-09 23:09:01 +0200 | [diff] [blame] | 91 | LOG_HELP_BOLD(" " PROG_NAME " --linux_perf_instr -- /usr/bin/tiffinfo -D " |
| 92 | _HF_FILE_PLACEHOLDER); |
Jagger | 3212737 | 2015-10-09 23:07:38 +0200 | [diff] [blame] | 93 | LOG_HELP(" Run the binary over a dynamic file, maximize total no. of branches:"); |
Jagger | 72f258b | 2015-10-09 23:09:01 +0200 | [diff] [blame] | 94 | LOG_HELP_BOLD(" " PROG_NAME " --linux_perf_branch -- /usr/bin/tiffinfo -D " |
| 95 | _HF_FILE_PLACEHOLDER); |
Robert Swiecki | 349cb9e | 2016-10-14 21:36:42 +0200 | [diff] [blame] | 96 | LOG_HELP(" Run the binary over a dynamic file, maximize unique code blocks via BTS:"); |
| 97 | LOG_HELP_BOLD(" " PROG_NAME " --linux_perf_bts_block -- /usr/bin/tiffinfo -D " |
| 98 | _HF_FILE_PLACEHOLDER); |
| 99 | LOG_HELP(" Run the binary over a dynamic file, maximize unique branches (edges) via BTS:"); |
Robert Swiecki | 43f0b28 | 2016-11-01 18:06:40 +0100 | [diff] [blame] | 100 | LOG_HELP_BOLD(" " PROG_NAME " --linux_perf_bts_edge -- /usr/bin/tiffinfo -D " |
| 101 | _HF_FILE_PLACEHOLDER); |
Robert Swiecki | 349cb9e | 2016-10-14 21:36:42 +0200 | [diff] [blame] | 102 | LOG_HELP |
Robert Swiecki | 8499c66 | 2016-11-01 18:02:52 +0100 | [diff] [blame] | 103 | (" Run the binary over a dynamic file, maximize unique code blocks via Intel Processor Trace (requires libipt.so):"); |
Robert Swiecki | 349cb9e | 2016-10-14 21:36:42 +0200 | [diff] [blame] | 104 | LOG_HELP_BOLD(" " PROG_NAME " --linux_perf_ipt_block -- /usr/bin/tiffinfo -D " |
Jagger | 72f258b | 2015-10-09 23:09:01 +0200 | [diff] [blame] | 105 | _HF_FILE_PLACEHOLDER); |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 106 | #endif /* defined(_HF_ARCH_LINUX) */ |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | static void cmdlineUsage(const char *pname, struct custom_option *opts) |
| 110 | { |
| 111 | cmdlineHelp(pname, opts); |
| 112 | exit(0); |
| 113 | } |
| 114 | |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 115 | rlim_t cmdlineParseRLimit(int res, const char *optarg, unsigned long mul) |
| 116 | { |
| 117 | struct rlimit cur; |
| 118 | if (getrlimit(res, &cur) == -1) { |
| 119 | PLOG_F("getrlimit(%d)", res); |
| 120 | } |
| 121 | if (strcasecmp(optarg, "max") == 0) { |
| 122 | return cur.rlim_max; |
| 123 | } |
| 124 | if (strcasecmp(optarg, "def") == 0) { |
| 125 | return cur.rlim_cur; |
| 126 | } |
Anestis Bechtsoudis | 413cb13 | 2016-02-07 12:59:00 +0200 | [diff] [blame] | 127 | if (util_isANumber(optarg) == false) { |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 128 | LOG_F("RLIMIT %d needs a numeric or 'max'/'def' value ('%s' provided)", res, optarg); |
| 129 | } |
| 130 | rlim_t val = strtoul(optarg, NULL, 0) * mul; |
Jagger | 2bd61b7 | 2015-10-10 05:23:32 +0200 | [diff] [blame] | 131 | if ((unsigned long)val == ULONG_MAX && errno != 0) { |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 132 | PLOG_F("strtoul('%s', 0)", optarg); |
| 133 | } |
| 134 | return val; |
| 135 | } |
| 136 | |
| 137 | bool cmdlineParse(int argc, char *argv[], honggfuzz_t * hfuzz) |
| 138 | { |
| 139 | /* *INDENT-OFF* */ |
| 140 | (*hfuzz) = (honggfuzz_t) { |
| 141 | .cmdline = NULL, |
Robert Swiecki | 72d2bef | 2016-01-19 14:39:26 +0100 | [diff] [blame] | 142 | .cmdline_txt[0] = '\0', |
Jagger | 1b2d482 | 2016-09-25 16:19:45 +0200 | [diff] [blame] | 143 | .inputDir = NULL, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 144 | .nullifyStdio = false, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 145 | .fuzzStdin = false, |
| 146 | .saveUnique = true, |
Robert Swiecki | 6c9f682 | 2016-03-14 16:12:27 +0100 | [diff] [blame] | 147 | .useScreen = true, |
| 148 | .useVerifier = false, |
| 149 | .timeStart = time(NULL), |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 150 | .fileExtn = "fuzz", |
| 151 | .workDir = ".", |
Jagger | 1b2d482 | 2016-09-25 16:19:45 +0200 | [diff] [blame] | 152 | .covDir = NULL, |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 153 | .origFlipRate = 0.001f, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 154 | .externalCommand = NULL, |
Robert Swiecki | ee266ac | 2016-10-03 02:25:59 +0200 | [diff] [blame] | 155 | .postExternalCommand = NULL, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 156 | .blacklistFile = NULL, |
| 157 | .blacklistCnt = 0, |
| 158 | .blacklist = NULL, |
Jagger | f4a6056 | 2016-09-25 15:40:23 +0200 | [diff] [blame] | 159 | .maxFileSz = 0UL, |
Jagger | ba92b4b | 2016-03-16 02:24:17 +0100 | [diff] [blame] | 160 | .tmOut = 10, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 161 | .mutationsMax = 0, |
| 162 | .threadsFinished = 0, |
Jagger | 2664f54 | 2016-09-28 14:37:00 +0200 | [diff] [blame] | 163 | .threadsMax = (sysconf(_SC_NPROCESSORS_ONLN) <= 1) ? 1 : sysconf(_SC_NPROCESSORS_ONLN) / 2, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 164 | .reportFile = NULL, |
| 165 | .asLimit = 0ULL, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 166 | .fileCnt = 0, |
Robert Swiecki | 05354ca | 2016-03-15 19:10:23 +0100 | [diff] [blame] | 167 | .lastFileIndex = 0, |
| 168 | .doneFileIndex = 0, |
Jagger | 80041fe | 2016-03-10 21:32:35 +0100 | [diff] [blame] | 169 | .clearEnv = false, |
Jagger | ab26e70 | 2016-03-22 04:28:00 +0100 | [diff] [blame] | 170 | .envs = { |
| 171 | [0 ... (ARRAYSIZE(hfuzz->envs) - 1)] = NULL, |
| 172 | }, |
Robert Swiecki | 0f937af | 2016-03-30 18:19:16 +0200 | [diff] [blame] | 173 | .persistent = false, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 174 | |
Robert Swiecki | 531438a | 2016-09-13 19:05:11 +0200 | [diff] [blame] | 175 | .dictionaryFile = NULL, |
| 176 | .dictionaryCnt = 0, |
| 177 | |
Robert Swiecki | 6c9f682 | 2016-03-14 16:12:27 +0100 | [diff] [blame] | 178 | .state = _HF_STATE_UNSET, |
Jagger | b7fa3ee | 2016-08-21 19:46:26 +0200 | [diff] [blame] | 179 | .feedback = NULL, |
Robert Swiecki | bc7532e | 2016-08-20 00:34:17 +0200 | [diff] [blame] | 180 | .bbFd = -1, |
Robert Swiecki | e586c1f | 2016-03-14 18:46:03 +0100 | [diff] [blame] | 181 | .dynfileq_mutex = PTHREAD_MUTEX_INITIALIZER, |
Robert Swiecki | 3bfc33c | 2016-03-14 18:12:41 +0100 | [diff] [blame] | 182 | .dynfileqCnt = 0U, |
Robert Swiecki | 6c9f682 | 2016-03-14 16:12:27 +0100 | [diff] [blame] | 183 | |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 184 | .mutationsCnt = 0, |
| 185 | .crashesCnt = 0, |
| 186 | .uniqueCrashesCnt = 0, |
Anestis Bechtsoudis | 79b799e | 2015-11-01 00:02:25 +0200 | [diff] [blame] | 187 | .verifiedCrashesCnt = 0, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 188 | .blCrashesCnt = 0, |
| 189 | .timeoutedCnt = 0, |
| 190 | |
Robert Swiecki | 6c9f682 | 2016-03-14 16:12:27 +0100 | [diff] [blame] | 191 | .dynFileMethod = _HF_DYNFILE_NONE, |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 192 | .sanCovCnts = { |
Jagger | ab26e70 | 2016-03-22 04:28:00 +0100 | [diff] [blame] | 193 | .hitBBCnt = 0ULL, |
| 194 | .totalBBCnt = 0ULL, |
| 195 | .dsoCnt = 0ULL, |
| 196 | .iDsoCnt = 0ULL, |
| 197 | .newBBCnt = 0ULL, |
| 198 | .crashesCnt = 0ULL, |
| 199 | }, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 200 | |
Anestis Bechtsoudis | a16f70f | 2016-01-03 13:03:21 +0200 | [diff] [blame] | 201 | .sanCov_mutex = PTHREAD_MUTEX_INITIALIZER, |
Robert Swiecki | 23ec02a | 2016-01-19 18:47:45 +0100 | [diff] [blame] | 202 | .sanOpts = { |
Jagger | ab26e70 | 2016-03-22 04:28:00 +0100 | [diff] [blame] | 203 | .asanOpts = NULL, |
| 204 | .msanOpts = NULL, |
| 205 | .ubsanOpts = NULL, |
Anestis Bechtsoudis | 61b5ab1 | 2016-01-08 16:07:02 +0200 | [diff] [blame] | 206 | }, |
Robert Swiecki | 6c9f682 | 2016-03-14 16:12:27 +0100 | [diff] [blame] | 207 | .useSanCov = false, |
Robert Swiecki | 6c9f682 | 2016-03-14 16:12:27 +0100 | [diff] [blame] | 208 | .covMetadata = NULL, |
Jagger | 247c3b4 | 2016-03-21 23:24:05 +0100 | [diff] [blame] | 209 | .msanReportUMRS = false, |
Robert Swiecki | 6c9f682 | 2016-03-14 16:12:27 +0100 | [diff] [blame] | 210 | |
Haris Andrianakis | c9a7133 | 2016-05-09 21:56:30 -0700 | [diff] [blame] | 211 | .report_mutex = PTHREAD_MUTEX_INITIALIZER, |
| 212 | |
Robert Swiecki | 6c9f682 | 2016-03-14 16:12:27 +0100 | [diff] [blame] | 213 | /* Linux code */ |
Robert Swiecki | fab6916 | 2016-03-31 15:41:36 +0200 | [diff] [blame] | 214 | .linux = { |
Jagger | ab26e70 | 2016-03-22 04:28:00 +0100 | [diff] [blame] | 215 | .hwCnts = { |
| 216 | .cpuInstrCnt = 0ULL, |
| 217 | .cpuBranchCnt = 0ULL, |
Jagger | ab26e70 | 2016-03-22 04:28:00 +0100 | [diff] [blame] | 218 | .bbCnt = 0ULL, |
| 219 | .newBBCnt = 0ULL, |
Jagger | 34789a7 | 2016-09-08 00:36:09 +0200 | [diff] [blame] | 220 | .softCntPc = 0ULL, |
| 221 | .softCntCmp = 0ULL, |
Jagger | ab26e70 | 2016-03-22 04:28:00 +0100 | [diff] [blame] | 222 | }, |
| 223 | .dynamicCutOffAddr = ~(0ULL), |
| 224 | .disableRandomization = true, |
| 225 | .ignoreAddr = NULL, |
| 226 | .numMajorFrames = 7, |
| 227 | .pid = 0, |
| 228 | .pidFile = NULL, |
| 229 | .pidCmd = NULL, |
Anestis Bechtsoudis | ba68b38 | 2016-10-29 20:44:15 +0300 | [diff] [blame] | 230 | .symsBlFile = NULL, |
| 231 | .symsBlCnt = 0, |
| 232 | .symsBl = NULL, |
| 233 | .symsWlFile = NULL, |
| 234 | .symsWlCnt = 0, |
| 235 | .symsWl = NULL, |
Jagger | ab26e70 | 2016-03-22 04:28:00 +0100 | [diff] [blame] | 236 | }, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 237 | }; |
| 238 | /* *INDENT-ON* */ |
| 239 | |
Robert Swiecki | 3bfc33c | 2016-03-14 18:12:41 +0100 | [diff] [blame] | 240 | TAILQ_INIT(&hfuzz->dynfileq); |
Robert Swiecki | 3a57226 | 2016-10-04 01:48:34 +0200 | [diff] [blame] | 241 | TAILQ_INIT(&hfuzz->dictq); |
Robert Swiecki | e8f8e8d | 2016-10-03 23:51:32 +0200 | [diff] [blame] | 242 | TAILQ_INIT(&hfuzz->fileq); |
Robert Swiecki | 3bfc33c | 2016-03-14 18:12:41 +0100 | [diff] [blame] | 243 | |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 244 | /* *INDENT-OFF* */ |
| 245 | struct custom_option custom_opts[] = { |
| 246 | {{"help", no_argument, NULL, 'h'}, "Help plz.."}, |
Jagger | 1b2d482 | 2016-09-25 16:19:45 +0200 | [diff] [blame] | 247 | {{"input", required_argument, NULL, 'f'}, "Path to a directory containing initial file corpus"}, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 248 | {{"nullify_stdio", no_argument, NULL, 'q'}, "Null-ify children's stdin, stdout, stderr; make them quiet"}, |
Jagger | 54c96a2 | 2016-03-30 23:13:30 +0200 | [diff] [blame] | 249 | {{"timeout", required_argument, NULL, 't'}, "Timeout in seconds (default: '10')"}, |
Jagger | 2664f54 | 2016-09-28 14:37:00 +0200 | [diff] [blame] | 250 | {{"threads", required_argument, NULL, 'n'}, "Number of concurrent fuzzing threads (default: number of CPUs / 2)"}, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 251 | {{"stdin_input", no_argument, NULL, 's'}, "Provide fuzzing input on STDIN, instead of ___FILE___"}, |
Jagger | 54c96a2 | 2016-03-30 23:13:30 +0200 | [diff] [blame] | 252 | {{"mutation_rate", required_argument, NULL, 'r'}, "Maximal mutation rate in relation to the file size, (default: '0.001')"}, |
Robert Swiecki | 03ef531 | 2015-10-09 18:25:40 +0200 | [diff] [blame] | 253 | {{"logfile", required_argument, NULL, 'l'}, "Log file"}, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 254 | {{"verbose", no_argument, NULL, 'v'}, "Disable ANSI console; use simple log output"}, |
Jagger | 5ff08ac | 2016-02-09 22:15:58 +0100 | [diff] [blame] | 255 | {{"verifier", no_argument, NULL, 'V'}, "Enable crashes verifier"}, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 256 | {{"debug_level", required_argument, NULL, 'd'}, "Debug level (0 - FATAL ... 4 - DEBUG), (default: '3' [INFO])"}, |
| 257 | {{"extension", required_argument, NULL, 'e'}, "Input file extension (e.g. 'swf'), (default: 'fuzz')"}, |
Anestis Bechtsoudis | bfcba12 | 2016-04-28 10:55:20 +0300 | [diff] [blame] | 258 | {{"workspace", required_argument, NULL, 'W'}, "Workspace directory to save crashes & runtime files (default: '.')"}, |
Robert Swiecki | d32018f | 2016-10-11 22:58:22 +0200 | [diff] [blame] | 259 | {{"covdir", required_argument, NULL, 0x103}, "New coverage is written to a separate directory (default: use the input directory)"}, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 260 | {{"wordlist", required_argument, NULL, 'w'}, "Wordlist file (tokens delimited by NUL-bytes)"}, |
| 261 | {{"stackhash_bl", required_argument, NULL, 'B'}, "Stackhashes blacklist file (one entry per line)"}, |
Robert Swiecki | ee266ac | 2016-10-03 02:25:59 +0200 | [diff] [blame] | 262 | {{"mutate_cmd", required_argument, NULL, 'c'}, "External command producing fuzz files (instead of internal mutators)"}, |
| 263 | {{"pprocess_cmd", required_argument, NULL, 0x104}, "External command postprocessing files produced by internal mutators"}, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 264 | {{"iterations", required_argument, NULL, 'N'}, "Number of fuzzing iterations (default: '0' [no limit])"}, |
Robert Swiecki | 03ef531 | 2015-10-09 18:25:40 +0200 | [diff] [blame] | 265 | {{"rlimit_as", required_argument, NULL, 0x100}, "Per process memory limit in MiB (default: '0' [no limit])"}, |
dyjakan | ebfd24e | 2015-10-16 19:24:32 +0100 | [diff] [blame] | 266 | {{"report", required_argument, NULL, 'R'}, "Write report to this file (default: '" _HF_REPORT_FILE "')"}, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 267 | {{"max_file_size", required_argument, NULL, 'F'}, "Maximal size of files processed by the fuzzer in bytes (default: '1048576')"}, |
Jagger | 80041fe | 2016-03-10 21:32:35 +0100 | [diff] [blame] | 268 | {{"clear_env", no_argument, NULL, 0x101}, "Clear all environment variables before executing the binary"}, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 269 | {{"env", required_argument, NULL, 'E'}, "Pass this environment variable, can be used multiple times"}, |
Jagger | 54c96a2 | 2016-03-30 23:13:30 +0200 | [diff] [blame] | 270 | {{"save_all", no_argument, NULL, 'u'}, "Save all test-cases (not only the unique ones) by appending the current time-stamp to the filenames"}, |
Jagger | 3db1d95 | 2016-03-10 02:02:46 +0100 | [diff] [blame] | 271 | {{"sancov", no_argument, NULL, 'C'}, "Enable sanitizer coverage feedback"}, |
Robert Swiecki | f05b1cd | 2016-11-01 18:05:45 +0100 | [diff] [blame] | 272 | {{"instrument", no_argument, NULL, 'z'}, "Enable compile-time instrumentation (link with libhfuzz/libhfuzz.a)"}, |
Jagger | 7ff92fa | 2016-03-22 04:13:50 +0100 | [diff] [blame] | 273 | {{"msan_report_umrs", no_argument, NULL, 0x102}, "Report MSAN's UMRS (uninitialized memory access)"}, |
Robert Swiecki | f05b1cd | 2016-11-01 18:05:45 +0100 | [diff] [blame] | 274 | {{"persistent", no_argument, NULL, 'P'}, "Enable persistent fuzzing (link with libhfuzz/libhfuzz.a)"}, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 275 | |
| 276 | #if defined(_HF_ARCH_LINUX) |
Anestis Bechtsoudis | fafb333 | 2016-10-31 08:57:16 +0200 | [diff] [blame] | 277 | {{"linux_symbols_bl", required_argument, NULL, 0x504}, "Symbols blacklist filter file (one entry per line)"}, |
| 278 | {{"linux_symbols_wl", required_argument, NULL, 0x505}, "Symbols whitelist filter file (one entry per line)"}, |
Anestis Bechtsoudis | 413cb13 | 2016-02-07 12:59:00 +0200 | [diff] [blame] | 279 | {{"linux_pid", required_argument, NULL, 'p'}, "Attach to a pid (and its thread group)"}, |
Robert Swiecki | fab6916 | 2016-03-31 15:41:36 +0200 | [diff] [blame] | 280 | {{"linux_file_pid", required_argument, NULL, 0x502}, "Attach to pid (and its thread group) read from file"}, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 281 | {{"linux_addr_low_limit", required_argument, NULL, 0x500}, "Address limit (from si.si_addr) below which crashes are not reported, (default: '0')"}, |
| 282 | {{"linux_keep_aslr", no_argument, NULL, 0x501}, "Don't disable ASLR randomization, might be useful with MSAN"}, |
Jagger | ae6a445 | 2015-10-14 17:34:43 +0200 | [diff] [blame] | 283 | {{"linux_perf_ignore_above", required_argument, NULL, 0x503}, "Ignore perf events which report IPs above this address"}, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 284 | {{"linux_perf_instr", no_argument, NULL, 0x510}, "Use PERF_COUNT_HW_INSTRUCTIONS perf"}, |
| 285 | {{"linux_perf_branch", no_argument, NULL, 0x511}, "Use PERF_COUNT_HW_BRANCH_INSTRUCTIONS perf"}, |
Jagger | 39bd2b0 | 2016-02-04 01:16:15 +0100 | [diff] [blame] | 286 | {{"linux_perf_bts_block", no_argument, NULL, 0x512}, "Use Intel BTS to count unique blocks"}, |
| 287 | {{"linux_perf_bts_edge", no_argument, NULL, 0x513}, "Use Intel BTS to count unique edges"}, |
Robert Swiecki | 8499c66 | 2016-11-01 18:02:52 +0100 | [diff] [blame] | 288 | {{"linux_perf_ipt_block", no_argument, NULL, 0x514}, "Use Intel Processor Trace to count unique blocks (requires libipt.so)"}, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 289 | #endif // defined(_HF_ARCH_LINUX) |
| 290 | {{0, 0, 0, 0}, NULL}, |
| 291 | }; |
| 292 | /* *INDENT-ON* */ |
| 293 | |
| 294 | struct option opts[ARRAYSIZE(custom_opts)]; |
| 295 | for (unsigned i = 0; i < ARRAYSIZE(custom_opts); i++) { |
| 296 | opts[i] = custom_opts[i].opt; |
| 297 | } |
| 298 | |
| 299 | enum llevel_t ll = INFO; |
| 300 | const char *logfile = NULL; |
| 301 | int opt_index = 0; |
| 302 | for (;;) { |
Jagger | 4aac9fe | 2016-08-28 17:35:48 +0200 | [diff] [blame] | 303 | int c = getopt_long(argc, argv, "-?hqvVsuPf:d:e:W:r:c:F:t:R:n:N:l:p:g:E:w:B:Cz", opts, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 304 | &opt_index); |
| 305 | if (c < 0) |
| 306 | break; |
| 307 | |
| 308 | switch (c) { |
| 309 | case 'h': |
| 310 | case '?': |
| 311 | cmdlineUsage(argv[0], custom_opts); |
| 312 | break; |
| 313 | case 'f': |
Jagger | 1b2d482 | 2016-09-25 16:19:45 +0200 | [diff] [blame] | 314 | hfuzz->inputDir = optarg; |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 315 | break; |
| 316 | case 'q': |
| 317 | hfuzz->nullifyStdio = true; |
| 318 | break; |
| 319 | case 'v': |
| 320 | hfuzz->useScreen = false; |
| 321 | break; |
Anestis Bechtsoudis | 0cde66f | 2015-10-11 19:37:11 -0700 | [diff] [blame] | 322 | case 'V': |
| 323 | hfuzz->useVerifier = true; |
| 324 | break; |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 325 | case 's': |
| 326 | hfuzz->fuzzStdin = true; |
| 327 | break; |
| 328 | case 'u': |
| 329 | hfuzz->saveUnique = false; |
| 330 | break; |
Robert Swiecki | 03ef531 | 2015-10-09 18:25:40 +0200 | [diff] [blame] | 331 | case 'l': |
| 332 | logfile = optarg; |
| 333 | break; |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 334 | case 'd': |
| 335 | ll = atoi(optarg); |
| 336 | break; |
| 337 | case 'e': |
| 338 | hfuzz->fileExtn = optarg; |
| 339 | break; |
| 340 | case 'W': |
| 341 | hfuzz->workDir = optarg; |
| 342 | break; |
| 343 | case 'r': |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 344 | hfuzz->origFlipRate = strtod(optarg, NULL); |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 345 | break; |
| 346 | case 'c': |
| 347 | hfuzz->externalCommand = optarg; |
| 348 | break; |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 349 | case 'C': |
| 350 | hfuzz->useSanCov = true; |
| 351 | break; |
Jagger | 4aac9fe | 2016-08-28 17:35:48 +0200 | [diff] [blame] | 352 | case 'z': |
| 353 | hfuzz->dynFileMethod |= _HF_DYNFILE_SOFT; |
| 354 | break; |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 355 | case 'F': |
| 356 | hfuzz->maxFileSz = strtoul(optarg, NULL, 0); |
| 357 | break; |
| 358 | case 't': |
| 359 | hfuzz->tmOut = atol(optarg); |
| 360 | break; |
| 361 | case 'R': |
| 362 | hfuzz->reportFile = optarg; |
| 363 | break; |
| 364 | case 'n': |
| 365 | hfuzz->threadsMax = atol(optarg); |
| 366 | break; |
| 367 | case 'N': |
| 368 | hfuzz->mutationsMax = atol(optarg); |
| 369 | break; |
Robert Swiecki | 03ef531 | 2015-10-09 18:25:40 +0200 | [diff] [blame] | 370 | case 0x100: |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 371 | hfuzz->asLimit = strtoull(optarg, NULL, 0); |
| 372 | break; |
Jagger | 80041fe | 2016-03-10 21:32:35 +0100 | [diff] [blame] | 373 | case 0x101: |
| 374 | hfuzz->clearEnv = true; |
| 375 | break; |
Jagger | 7ff92fa | 2016-03-22 04:13:50 +0100 | [diff] [blame] | 376 | case 0x102: |
| 377 | hfuzz->msanReportUMRS = true; |
| 378 | break; |
Robert Swiecki | dac8cf1 | 2016-09-22 15:36:28 +0200 | [diff] [blame] | 379 | case 0x103: |
Jagger | 1b2d482 | 2016-09-25 16:19:45 +0200 | [diff] [blame] | 380 | hfuzz->covDir = optarg; |
Robert Swiecki | dac8cf1 | 2016-09-22 15:36:28 +0200 | [diff] [blame] | 381 | break; |
Robert Swiecki | ee266ac | 2016-10-03 02:25:59 +0200 | [diff] [blame] | 382 | case 0x104: |
| 383 | hfuzz->postExternalCommand = optarg; |
| 384 | break; |
Robert Swiecki | fab6916 | 2016-03-31 15:41:36 +0200 | [diff] [blame] | 385 | case 'P': |
Robert Swiecki | 0f937af | 2016-03-30 18:19:16 +0200 | [diff] [blame] | 386 | hfuzz->persistent = true; |
| 387 | break; |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 388 | case 'p': |
Anestis Bechtsoudis | 413cb13 | 2016-02-07 12:59:00 +0200 | [diff] [blame] | 389 | if (util_isANumber(optarg) == false) { |
Jagger | 9c4d162 | 2015-10-16 01:40:17 +0200 | [diff] [blame] | 390 | LOG_E("-p '%s' is not a number", optarg); |
| 391 | return false; |
| 392 | } |
Jagger | 247c3b4 | 2016-03-21 23:24:05 +0100 | [diff] [blame] | 393 | hfuzz->linux.pid = atoi(optarg); |
| 394 | if (hfuzz->linux.pid < 1) { |
| 395 | LOG_E("-p '%d' is invalid", hfuzz->linux.pid); |
Jagger | 9c4d162 | 2015-10-16 01:40:17 +0200 | [diff] [blame] | 396 | return false; |
| 397 | } |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 398 | break; |
Robert Swiecki | fab6916 | 2016-03-31 15:41:36 +0200 | [diff] [blame] | 399 | case 0x502: |
Jagger | 247c3b4 | 2016-03-21 23:24:05 +0100 | [diff] [blame] | 400 | hfuzz->linux.pidFile = optarg; |
Anestis Bechtsoudis | 413cb13 | 2016-02-07 12:59:00 +0200 | [diff] [blame] | 401 | break; |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 402 | case 'E': |
| 403 | for (size_t i = 0; i < ARRAYSIZE(hfuzz->envs); i++) { |
| 404 | if (hfuzz->envs[i] == NULL) { |
| 405 | hfuzz->envs[i] = optarg; |
| 406 | break; |
| 407 | } |
| 408 | } |
| 409 | break; |
| 410 | case 'w': |
| 411 | hfuzz->dictionaryFile = optarg; |
| 412 | break; |
| 413 | case 'B': |
| 414 | hfuzz->blacklistFile = optarg; |
| 415 | break; |
| 416 | case 0x500: |
Jagger | 247c3b4 | 2016-03-21 23:24:05 +0100 | [diff] [blame] | 417 | hfuzz->linux.ignoreAddr = (void *)strtoul(optarg, NULL, 0); |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 418 | break; |
| 419 | case 0x501: |
Jagger | 247c3b4 | 2016-03-21 23:24:05 +0100 | [diff] [blame] | 420 | hfuzz->linux.disableRandomization = false; |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 421 | break; |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 422 | case 0x503: |
Jagger | 247c3b4 | 2016-03-21 23:24:05 +0100 | [diff] [blame] | 423 | hfuzz->linux.dynamicCutOffAddr = strtoull(optarg, NULL, 0); |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 424 | break; |
Anestis Bechtsoudis | ba68b38 | 2016-10-29 20:44:15 +0300 | [diff] [blame] | 425 | case 0x504: |
| 426 | hfuzz->linux.symsBlFile = optarg; |
| 427 | break; |
| 428 | case 0x505: |
| 429 | hfuzz->linux.symsWlFile = optarg; |
| 430 | break; |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 431 | case 0x510: |
| 432 | hfuzz->dynFileMethod |= _HF_DYNFILE_INSTR_COUNT; |
| 433 | break; |
| 434 | case 0x511: |
| 435 | hfuzz->dynFileMethod |= _HF_DYNFILE_BRANCH_COUNT; |
| 436 | break; |
| 437 | case 0x512: |
Jagger | 3abc560 | 2016-02-04 00:53:43 +0100 | [diff] [blame] | 438 | hfuzz->dynFileMethod |= _HF_DYNFILE_BTS_BLOCK; |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 439 | break; |
| 440 | case 0x513: |
Jagger | 3abc560 | 2016-02-04 00:53:43 +0100 | [diff] [blame] | 441 | hfuzz->dynFileMethod |= _HF_DYNFILE_BTS_EDGE; |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 442 | break; |
| 443 | case 0x514: |
Jagger | 39bd2b0 | 2016-02-04 01:16:15 +0100 | [diff] [blame] | 444 | hfuzz->dynFileMethod |= _HF_DYNFILE_IPT_BLOCK; |
| 445 | break; |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 446 | default: |
| 447 | cmdlineUsage(argv[0], custom_opts); |
| 448 | return false; |
| 449 | break; |
| 450 | } |
| 451 | } |
Jagger | 72f258b | 2015-10-09 23:09:01 +0200 | [diff] [blame] | 452 | |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 453 | if (logInitLogFile(logfile, ll) == false) { |
| 454 | return false; |
| 455 | } |
| 456 | |
| 457 | hfuzz->cmdline = &argv[optind]; |
| 458 | if (hfuzz->cmdline[0] == NULL) { |
| 459 | LOG_E("No fuzz command provided"); |
| 460 | cmdlineUsage(argv[0], custom_opts); |
| 461 | return false; |
| 462 | } |
| 463 | |
Robert Swiecki | 0f937af | 2016-03-30 18:19:16 +0200 | [diff] [blame] | 464 | if (!hfuzz->fuzzStdin && !hfuzz->persistent && !checkFor_FILE_PLACEHOLDER(hfuzz->cmdline)) { |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 465 | LOG_E("You must specify '" _HF_FILE_PLACEHOLDER |
Robert Swiecki | 0f937af | 2016-03-30 18:19:16 +0200 | [diff] [blame] | 466 | "' when the -s (stdin fuzzing) or --persistent options are not set"); |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 467 | return false; |
| 468 | } |
| 469 | |
Robert Swiecki | 71b7372 | 2016-09-05 15:18:25 +0200 | [diff] [blame] | 470 | if (hfuzz->threadsMax >= _HF_THREAD_MAX) { |
| 471 | LOG_E("Too many fuzzing threads specified %zu (>= _HF_THREAD_MAX (%u))", hfuzz->threadsMax, |
| 472 | _HF_THREAD_MAX); |
| 473 | return false; |
| 474 | } |
| 475 | |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 476 | if (strchr(hfuzz->fileExtn, '/')) { |
| 477 | LOG_E("The file extension contains the '/' character: '%s'", hfuzz->fileExtn); |
| 478 | return false; |
| 479 | } |
Anestis Bechtsoudis | be0ac7b | 2015-12-26 15:38:47 +0200 | [diff] [blame] | 480 | |
Anestis Bechtsoudis | 8f4aa61 | 2015-12-27 12:06:19 +0200 | [diff] [blame] | 481 | if (hfuzz->workDir[0] != '.' || strlen(hfuzz->workDir) > 2) { |
Anestis Bechtsoudis | c8e7f6e | 2015-12-26 14:48:48 +0200 | [diff] [blame] | 482 | if (!files_exists(hfuzz->workDir)) { |
| 483 | LOG_E("Provided workspace directory '%s' doesn't exist", hfuzz->workDir); |
| 484 | return false; |
| 485 | } |
| 486 | } |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 487 | |
Jagger | 247c3b4 | 2016-03-21 23:24:05 +0100 | [diff] [blame] | 488 | if (hfuzz->linux.pid > 0 || hfuzz->linux.pidFile) { |
| 489 | LOG_I("PID=%d specified, lowering maximum number of concurrent threads to 1", |
| 490 | hfuzz->linux.pid); |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 491 | hfuzz->threadsMax = 1; |
| 492 | } |
| 493 | |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 494 | if (hfuzz->origFlipRate == 0.0L && hfuzz->useVerifier) { |
Anestis Bechtsoudis | c8e7f6e | 2015-12-26 14:48:48 +0200 | [diff] [blame] | 495 | LOG_I("Verifier enabled with 0.0 flipRate, activating dry run mode"); |
Anestis Bechtsoudis | 46ea10e | 2015-11-07 18:16:25 +0200 | [diff] [blame] | 496 | } |
| 497 | |
Jagger | 1b2d482 | 2016-09-25 16:19:45 +0200 | [diff] [blame] | 498 | LOG_I("inputDir '%s', nullifyStdio: %s, fuzzStdin: %s, saveUnique: %s, flipRate: %lf, " |
Jagger | 247c3b4 | 2016-03-21 23:24:05 +0100 | [diff] [blame] | 499 | "externalCommand: '%s', tmOut: %ld, mutationsMax: %zu, threadsMax: %zu, fileExtn '%s', " |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 500 | "memoryLimit: 0x%" PRIx64 "(MiB), fuzzExe: '%s', fuzzedPid: %d", |
Jagger | 1b2d482 | 2016-09-25 16:19:45 +0200 | [diff] [blame] | 501 | hfuzz->inputDir, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 502 | cmdlineYesNo(hfuzz->nullifyStdio), cmdlineYesNo(hfuzz->fuzzStdin), |
Robert Swiecki | a96d78d | 2016-03-14 16:50:50 +0100 | [diff] [blame] | 503 | cmdlineYesNo(hfuzz->saveUnique), hfuzz->origFlipRate, |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 504 | hfuzz->externalCommand == NULL ? "NULL" : hfuzz->externalCommand, hfuzz->tmOut, |
Jagger | 247c3b4 | 2016-03-21 23:24:05 +0100 | [diff] [blame] | 505 | hfuzz->mutationsMax, hfuzz->threadsMax, hfuzz->fileExtn, |
| 506 | hfuzz->asLimit, hfuzz->cmdline[0], hfuzz->linux.pid); |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 507 | |
Robert Swiecki | 2aaa52b | 2016-01-19 14:40:47 +0100 | [diff] [blame] | 508 | snprintf(hfuzz->cmdline_txt, sizeof(hfuzz->cmdline_txt), "%s", hfuzz->cmdline[0]); |
Robert Swiecki | 72d2bef | 2016-01-19 14:39:26 +0100 | [diff] [blame] | 509 | for (size_t i = 1; hfuzz->cmdline[i]; i++) { |
| 510 | util_ssnprintf(hfuzz->cmdline_txt, sizeof(hfuzz->cmdline_txt), " %s", hfuzz->cmdline[i]); |
Robert Swiecki | f2d9c3a | 2016-11-03 02:13:54 +0100 | [diff] [blame] | 511 | if (strlen(hfuzz->cmdline_txt) == (sizeof(hfuzz->cmdline_txt) - 1)) { |
| 512 | hfuzz->cmdline_txt[sizeof(hfuzz->cmdline_txt) - 3] = '.'; |
| 513 | hfuzz->cmdline_txt[sizeof(hfuzz->cmdline_txt) - 2] = '.'; |
| 514 | hfuzz->cmdline_txt[sizeof(hfuzz->cmdline_txt) - 1] = '.'; |
| 515 | } |
Robert Swiecki | 72d2bef | 2016-01-19 14:39:26 +0100 | [diff] [blame] | 516 | } |
| 517 | |
Robert Swiecki | a88f96f | 2015-10-09 16:47:39 +0200 | [diff] [blame] | 518 | return true; |
| 519 | } |