Skip to content

[Low] Arbitrary C code injection via unsanitized invariant pointer symbols in generated fuzzer.c #13

@donjon-cerberus-sandbox

Description

@donjon-cerberus-sandbox

Location

  • File: src/cgen/emit.zig
  • Lines: 278-282

Classification

Property Value
Severity High
Category Other
CWE CWE-CWE-94
OWASP A03:2021-Injection
Confidence Suspected
Likelihood Medium

Technical Description

Pointer target names from invariants are treated as trusted identifiers and emitted verbatim into generated C code. Invariant.applyToGlobals collects unknown .pointers targets from the attacker-controlled .zon invariant and stores them in func_symbols; emit.writeFuzzerC then interpolates each raw string into an extern declaration, and emitDomainTables later emits &<symbol> initializers for the same names. Because these strings are not validated as C identifiers, a crafted invariant can inject arbitrary C syntax into fuzzer.c. In workflows that automatically generate and compile the emitted fuzzer, this becomes build-time code injection and can lead to arbitrary code execution on the build host.

Vulnerable Code

for (func_symbols) |sym| {
    const func_decl = try std.fmt.allocPrint(allocator, "extern void {s}(void);\n", .{sym});
    defer allocator.free(func_decl);
    try file.writeAll(func_decl);
}

Impact

User input: attacker who can provide or modify the .zon invariant file can inject arbitrary C code into generated output, which may execute in CI/build systems when fuzzer.c is compiled or when the resulting binary is run. This can compromise developer workstations or build runners and poison generated fuzzing artifacts.

Remediation

Treat invariant pointer names as untrusted input. Before storing or emitting them, require them to match a strict C identifier pattern (^[A-Za-z_][A-Za-z0-9_]*$). Reject invariants containing invalid symbol names instead of interpolating raw strings into C templates.


Created by Cerberus Merlin

Metadata

Metadata

Assignees

No one assigned

    Labels

    securitySecurity findingwontfixThis will not be worked on

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions