about summary refs log tree commit diff
path: root/src/afl-as.c
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2023-04-12 10:54:08 +0200
committerGitHub <noreply@github.com>2023-04-12 10:54:08 +0200
commit4f2d9eeaaa6b702ef28eb883f9000321eaf1fe9b (patch)
tree125cecc79c148552844723e95ddd246bf918d6fc /src/afl-as.c
parent7101192865893e00b9029d0cb898a3ca3015d50b (diff)
parent743ae507756db0707a213cd8272b219b0de0f514 (diff)
downloadafl++-4f2d9eeaaa6b702ef28eb883f9000321eaf1fe9b.tar.gz
Merge pull request #1700 from AFLplusplus/dev
push to stable
Diffstat (limited to 'src/afl-as.c')
-rw-r--r--src/afl-as.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/afl-as.c b/src/afl-as.c
index a0eb612f..772e31b3 100644
--- a/src/afl-as.c
+++ b/src/afl-as.c
@@ -93,7 +93,7 @@ static u8 use_64bit = 0;
 static void edit_params(int argc, char **argv) {
 
   u8 *tmp_dir = getenv("TMPDIR"), *afl_as = getenv("AFL_AS");
-  u32 i;
+  u32 i, input_index;
 
 #ifdef __APPLE__
 
@@ -142,7 +142,23 @@ static void edit_params(int argc, char **argv) {
 
   as_params[argc] = 0;
 
-  for (i = 1; (s32)i < argc - 1; i++) {
+  /* Find the input file.  It's usually located near the end.
+     Assume there won't be any arguments referring to files after the input
+     file, e.g. as input.s -o output.o */
+  for (input_index = argc - 1; input_index > 0; input_index--) {
+
+    input_file = argv[input_index];
+    /* Clang may add debug arguments after the input file. */
+    if (strncmp(input_file, "-g", 2)) break;
+
+  }
+
+  if (input_index == 0)
+    FATAL("Could not find input file (not called through afl-gcc?)");
+
+  for (i = 1; (s32)i < argc; i++) {
+
+    if (i == input_index) continue;
 
     if (!strcmp(argv[i], "--64")) {
 
@@ -194,8 +210,6 @@ static void edit_params(int argc, char **argv) {
 
 #endif                                                         /* __APPLE__ */
 
-  input_file = argv[argc - 1];
-
   if (input_file[0] == '-') {
 
     if (!strcmp(input_file + 1, "-version")) {