From c0d98766384ab702d63a61d094dbc026b797df59 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Sun, 18 Aug 2024 04:16:40 +0000 Subject: [PATCH] Report how to reproduce the crash found by differential fuzzing --- FuzzTesting/README.md | 2 +- FuzzTesting/differential.py | 6 ++++-- Sources/SystemExtras/FileAtOperations.swift | 4 ++-- Sources/SystemExtras/Vendor/Exports.swift | 2 +- Sources/WASI/Platform/Entry.swift | 2 +- Sources/WASI/Platform/SandboxPrimitives/Open.swift | 8 ++++---- .../CanonicalABI/StaticCanonicalDeallocation.swift | 6 +++--- .../CanonicalABI/StaticCanonicalLowering.swift | 2 +- .../HostGenerators/HostExportFunction.swift | 2 +- Tests/WITTests/Semantics/ValidationTests.swift | 4 ++-- 10 files changed, 20 insertions(+), 18 deletions(-) diff --git a/FuzzTesting/README.md b/FuzzTesting/README.md index 26dc6962..8d3f6b60 100644 --- a/FuzzTesting/README.md +++ b/FuzzTesting/README.md @@ -7,7 +7,7 @@ This subdirectory contains some [libFuzzer](https://www.llvm.org/docs/LibFuzzer. ## Requirements -- [Open Source Swift Toolchain](https://swift.org/install) - Xcode toolchain does not contain fuzzing supoort, so you need to install the open source toolchain. +- [Open Source Swift Toolchain](https://swift.org/install) - Xcode toolchain does not contain fuzzing support, so you need to install the open source toolchain. - [wasm-tools](https://github.com/bytecodealliance/wasm-tools) - Required to generate random seed corpora ## libFuzzer-based Fuzzing Targets diff --git a/FuzzTesting/differential.py b/FuzzTesting/differential.py index 5b717941..d5d4fe35 100755 --- a/FuzzTesting/differential.py +++ b/FuzzTesting/differential.py @@ -50,11 +50,13 @@ def run(args): # If the target program fails, save the wasm file crash_file = os.path.join(fail_dir, f"diff-{i}.wasm") shutil.copy(wasm_file, crash_file) - print(f"Found crash in iteration {i}") + print(f"Found crash in iteration {i};" + " reproduce with {args.program} {crash_file}") except subprocess.TimeoutExpired: timeout_file = os.path.join(fail_dir, f"timeout-{i}.wasm") shutil.copy(wasm_file, timeout_file) - print(f"Timeout in iteration {i}") + print(f"Timeout in iteration {i};" + " reproduce with {args.program} {timeout_file})") except KeyboardInterrupt: print("Interrupted by user") break diff --git a/Sources/SystemExtras/FileAtOperations.swift b/Sources/SystemExtras/FileAtOperations.swift index e0b50089..e0690103 100644 --- a/Sources/SystemExtras/FileAtOperations.swift +++ b/Sources/SystemExtras/FileAtOperations.swift @@ -271,7 +271,7 @@ extension FileDescriptor { /// Create a symbolic link relative to a directory file descriptor /// /// - Parameters: - /// - original: The path to be refered by the created symbolic link. + /// - original: The path to be referred by the created symbolic link. /// - link: The relative location of the symbolic link to create /// /// The corresponding C function is `symlinkat`. @@ -287,7 +287,7 @@ extension FileDescriptor { /// Create a symbolic link relative to a directory file descriptor /// /// - Parameters: - /// - original: The path to be refered by the created symbolic link. + /// - original: The path to be referred by the created symbolic link. /// - link: The relative location of the symbolic link to create /// /// The corresponding C function is `symlinkat`. diff --git a/Sources/SystemExtras/Vendor/Exports.swift b/Sources/SystemExtras/Vendor/Exports.swift index 6e578f57..fcfbb807 100644 --- a/Sources/SystemExtras/Vendor/Exports.swift +++ b/Sources/SystemExtras/Vendor/Exports.swift @@ -80,7 +80,7 @@ internal func system_platform_strlen(_ s: UnsafePointer) #endif } -// Interop between String and platfrom string +// Interop between String and platform string extension String { internal func _withPlatformString( _ body: (UnsafePointer) throws -> Result diff --git a/Sources/WASI/Platform/Entry.swift b/Sources/WASI/Platform/Entry.swift index 1ed82933..420a7661 100644 --- a/Sources/WASI/Platform/Entry.swift +++ b/Sources/WASI/Platform/Entry.swift @@ -78,7 +78,7 @@ extension FdWASIEntry { try WASIAbi.FileType(platformFileType: self.fd.attributes().fileType) } - /// Returns the current file desciptor status + /// Returns the current file descriptor status func status() throws -> WASIAbi.Fdflags { return try WASIAbi.Errno.translatingPlatformErrno { WASIAbi.Fdflags(platformOpenOptions: try self.fd.status()) diff --git a/Sources/WASI/Platform/SandboxPrimitives/Open.swift b/Sources/WASI/Platform/SandboxPrimitives/Open.swift index 421d940f..c6d4c293 100644 --- a/Sources/WASI/Platform/SandboxPrimitives/Open.swift +++ b/Sources/WASI/Platform/SandboxPrimitives/Open.swift @@ -40,16 +40,16 @@ struct PathResolution { let options: FileDescriptor.OpenOptions let mode: FileDescriptor.AccessMode if !self.components.isEmpty { - var intermediateOtions: FileDescriptor.OpenOptions = [] + var intermediateOptions: FileDescriptor.OpenOptions = [] #if !os(Windows) // When trying to open an intermediate directory, // we can assume it's directory. - intermediateOtions.insert(.directory) + intermediateOptions.insert(.directory) // FIXME: Resolve symlink in safe way - intermediateOtions.insert(.noFollow) + intermediateOptions.insert(.noFollow) #endif - options = intermediateOtions + options = intermediateOptions mode = .readOnly } else { options = self.options diff --git a/Sources/WITOverlayGenerator/CanonicalABI/StaticCanonicalDeallocation.swift b/Sources/WITOverlayGenerator/CanonicalABI/StaticCanonicalDeallocation.swift index 65f391a4..4d9bb01b 100644 --- a/Sources/WITOverlayGenerator/CanonicalABI/StaticCanonicalDeallocation.swift +++ b/Sources/WITOverlayGenerator/CanonicalABI/StaticCanonicalDeallocation.swift @@ -15,15 +15,15 @@ struct StaticCanonicalDeallocation: CanonicalDeallocation { pointer: Operand, length: Operand, element: WITType, deallocateElement: (Pointer) throws -> Void ) throws { - let deallocElemenetVar = builder.variable("deallocElement") - printer.write(line: "let \(deallocElemenetVar): (UnsafeMutableRawPointer) -> Void = {") + let deallocElementVar = builder.variable("deallocElement") + printer.write(line: "let \(deallocElementVar): (UnsafeMutableRawPointer) -> Void = {") try printer.indent { printer.write(line: "_ = $0") try deallocateElement(.init(basePointerVar: "$0", offset: 0)) } printer.write(line: "}") printer.write( - line: "Prelude.deallocateList(pointer: \(pointer), length: \(length), elementSize: \(CanonicalABI.size(type: element)), deallocateElement: \(deallocElemenetVar))" + line: "Prelude.deallocateList(pointer: \(pointer), length: \(length), elementSize: \(CanonicalABI.size(type: element)), deallocateElement: \(deallocElementVar))" ) } diff --git a/Sources/WITOverlayGenerator/CanonicalABI/StaticCanonicalLowering.swift b/Sources/WITOverlayGenerator/CanonicalABI/StaticCanonicalLowering.swift index 78127374..3953624b 100644 --- a/Sources/WITOverlayGenerator/CanonicalABI/StaticCanonicalLowering.swift +++ b/Sources/WITOverlayGenerator/CanonicalABI/StaticCanonicalLowering.swift @@ -188,7 +188,7 @@ extension StaticCanonicalLowering { return .accessField(value, name: "bitPattern") case (.i64, .i32), (.i64, .f32), (.f64, .i32), (.f64, .f32): - fatalError("Should not trucate while casting") + fatalError("Should not truncate while casting") } } } diff --git a/Sources/WITOverlayGenerator/HostGenerators/HostExportFunction.swift b/Sources/WITOverlayGenerator/HostGenerators/HostExportFunction.swift index 8be2396e..28a4f900 100644 --- a/Sources/WITOverlayGenerator/HostGenerators/HostExportFunction.swift +++ b/Sources/WITOverlayGenerator/HostGenerators/HostExportFunction.swift @@ -259,7 +259,7 @@ struct HostExportFunction { let optionsVar = builder.variable("options") printer.write(line: "let \(optionsVar) = CanonicalOptions._derive(from: instance, exportName: \"\(name.abiName)\")") printer.write(line: "let \(context.contextVar) = CanonicalCallContext(options: \(optionsVar), instance: instance, runtime: runtime)") - // Supress unused variable warning for "context" + // Suppress unused variable warning for "context" printer.write(line: "_ = \(context.contextVar)") let arguments = try printLowerArguments( diff --git a/Tests/WITTests/Semantics/ValidationTests.swift b/Tests/WITTests/Semantics/ValidationTests.swift index 6b2c30b0..d00198c7 100644 --- a/Tests/WITTests/Semantics/ValidationTests.swift +++ b/Tests/WITTests/Semantics/ValidationTests.swift @@ -112,7 +112,7 @@ class ValidationTests: XCTestCase { type a = u8 type b = a } - // a shoud not be visible here + // a should not be visible here type c = a } """, @@ -130,7 +130,7 @@ class ValidationTests: XCTestCase { type a = u8 type b = a } - // a shoud not be visible here + // a should not be visible here type c = a } """,