Skip to content

Commit 781c051

Browse files
committed
Add RUZZY_ARGV0 to support libFuzzer re-execution
1 parent 8551c5b commit 781c051

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

entrypoint.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/bin/bash
22

3+
SCRIPT_PATH="$(cd "$(dirname "$0")" && pwd)/$(basename "$0")"
4+
35
LD_PRELOAD=$(ruby -e 'require "ruzzy"; print Ruzzy::ASAN_PATH') \
4-
ruby -e 'require "ruzzy"; Ruzzy.dummy' -- "$@"
6+
RUZZY_ARGV0="$SCRIPT_PATH" ruby -e 'require "ruzzy"; Ruzzy.dummy' -- "$@"

lib/ruzzy.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
module Ruzzy
88
require 'cruzzy/cruzzy'
99

10-
DEFAULT_ARGS = [$PROGRAM_NAME] + ARGV
10+
# libFuzzer features like -merge and -fork re-execute argv[0] via system().
11+
# RUZZY_ARGV0 allows a wrapper script (e.g. entrypoint.sh) to advertise its
12+
# own path as argv[0], so re-execution goes through the wrapper that sets
13+
# LD_PRELOAD and other required environment.
14+
ARGV0 = ENV.fetch('RUZZY_ARGV0', $PROGRAM_NAME)
15+
DEFAULT_ARGS = [ARGV0] + ARGV
1116
EXT_PATH = Pathname.new(__FILE__).parent.parent / 'ext' / 'cruzzy'
1217
ASAN_PATH = (EXT_PATH / 'asan_with_fuzzer.so').to_s
1318
UBSAN_PATH = (EXT_PATH / 'ubsan_with_fuzzer.so').to_s

0 commit comments

Comments
 (0)