Skip to content

Commit e263818

Browse files
author
Samuel Groß
committed
Store terminating signal in a comment instead of the filename for crashes
This helps for non-reproducible crashes as it makes sure that the original termination signal is not lost. Also fixed a bug that caused crashing samples to not be minimized properly.
1 parent bc057d1 commit e263818

File tree

6 files changed

+15
-13
lines changed

6 files changed

+15
-13
lines changed

Sources/Fuzzilli/Core/Events.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class Events {
5353
public let InvalidProgramFound = Event<Program>()
5454

5555
/// Signals that a crashing program has been found. Dispatched after the crashing program has been minimized.
56-
public let CrashFound = Event<(program: Program, behaviour: CrashBehaviour, signal: Int, isUnique: Bool, origin: ProgramOrigin)>()
56+
public let CrashFound = Event<(program: Program, behaviour: CrashBehaviour, isUnique: Bool, origin: ProgramOrigin)>()
5757

5858
/// Signals that a program causing a timeout has been found.
5959
public let TimeOutFound = Event<Program>()

Sources/Fuzzilli/Core/ProgramOrigin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import Foundation
1616

1717
// Enum to identify the origin of a Program.
18-
public enum ProgramOrigin {
18+
public enum ProgramOrigin: Equatable {
1919
// The program was generated by this instance.
2020
case local
2121

Sources/Fuzzilli/Evaluation/ProgramCoverageEvaluator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public class ProgramCoverageEvaluator: ComponentBase, ProgramEvaluator {
162162
}
163163

164164
}
165-
165+
166166
public func evaluateCrash(_ execution: Execution) -> ProgramAspects? {
167167
assert(execution.outcome.isCrash())
168168
let result = libcoverage.cov_evaluate_crash(&context)
@@ -184,6 +184,8 @@ public class ProgramCoverageEvaluator: ComponentBase, ProgramEvaluator {
184184
}
185185

186186
if let edgeSet = aspects as? CovEdgeSet {
187+
// We don't minimize crashes based on the coverage, only based on the crash outcome itself
188+
assert(!aspects.outcome.isCrash())
187189
let result = libcoverage.cov_compare_equal(&context, edgeSet.edges, edgeSet.count)
188190
if result == -1 {
189191
logger.error("Could not compare progam executions")

Sources/Fuzzilli/Fuzzer.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public class Fuzzer {
339339
processCrash(program, withSignal: termsig, withStderr: execution.stderr, origin: origin)
340340
} else {
341341
// Non-deterministic crash
342-
dispatchEvent(events.CrashFound, data: (program, behaviour: .flaky, signal: 0, isUnique: true, origin: origin))
342+
dispatchEvent(events.CrashFound, data: (program, behaviour: .flaky, isUnique: true, origin: origin))
343343
}
344344
}
345345

@@ -597,19 +597,21 @@ public class Fuzzer {
597597
/// Process a program that causes a crash.
598598
func processCrash(_ program: Program, withSignal termsig: Int, withStderr stderr: String, origin: ProgramOrigin) {
599599
func processCommon(_ program: Program) {
600-
let hasStderrComment = program.comments.at(.footer)?.contains("STDERR") ?? false
601-
if !hasStderrComment {
602-
// Append a comment containing the content of stderr the first time a crash occurred
600+
let hasCrashInfo = program.comments.at(.footer)?.contains("CRASH INFO") ?? false
601+
if !hasCrashInfo {
602+
program.comments.add("CRASH INFO\n==========\n", at: .footer)
603+
program.comments.add("TERMSIG: \(termsig)\n", at: .footer)
603604
program.comments.add("STDERR:\n" + stderr, at: .footer)
604605
}
606+
assert(program.comments.at(.footer)?.contains("CRASH INFO") ?? false)
605607

606608
// Check for uniqueness only after minimization
607609
let execution = execute(program, withTimeout: self.config.timeout * 2)
608610
if case .crashed = execution.outcome {
609611
let isUnique = evaluator.evaluateCrash(execution) != nil
610-
dispatchEvent(events.CrashFound, data: (program, .deterministic, termsig, isUnique, origin))
612+
dispatchEvent(events.CrashFound, data: (program, .deterministic, isUnique, origin))
611613
} else {
612-
dispatchEvent(events.CrashFound, data: (program, .flaky, termsig, true, origin))
614+
dispatchEvent(events.CrashFound, data: (program, .flaky, true, origin))
613615
}
614616
}
615617

Sources/Fuzzilli/Minimization/Verifier.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ class ReductionVerifier {
5555
var stillHasAspects = false
5656
fuzzer.sync {
5757
let execution = fuzzer.execute(Program(with: code), withTimeout: fuzzer.config.timeout * 2)
58-
if execution.outcome == .succeeded {
59-
stillHasAspects = fuzzer.evaluator.hasAspects(execution, aspects)
60-
}
58+
stillHasAspects = fuzzer.evaluator.hasAspects(execution, aspects)
6159
}
6260

6361
if stillHasAspects {

Sources/Fuzzilli/Modules/Storage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class Storage: Module {
6464
}
6565

6666
fuzzer.registerEventListener(for: fuzzer.events.CrashFound) { ev in
67-
let filename = "program_\(self.formatDate())_\(ev.program.id)_\(ev.behaviour.rawValue)_\(ev.signal)"
67+
let filename = "program_\(self.formatDate())_\(ev.program.id)_\(ev.behaviour.rawValue)"
6868
if ev.isUnique {
6969
self.storeProgram(ev.program, as: filename, in: self.crashesDir)
7070
} else {

0 commit comments

Comments
 (0)