From 85c573157db1baae51178263fe3289c8329e6dc2 Mon Sep 17 00:00:00 2001 From: Anton Lindqvist Date: Tue, 21 May 2019 23:17:22 +0200 Subject: pkg/csource: add ability to annotate syscalls using comments in C reproducers Providing additional info, especially regarding syscall arguments, in reproducers can be helpful. An example is device numbers passed to mknod(2). This commit introduces an optional annotate function on a per target basis. Example for the OpenBSD target: $ cat prog.in mknod(0x0, 0x0, 0x4503) getpid() $ syz-prog2c -prog prog.in int main(void) { syscall(SYS_mmap, 0x20000000, 0x1000000, 3, 0x1012, -1, 0, 0); syscall(SYS_mknod, 0, 0, 0x4503); /* major = 69, minor = 3 */ syscall(SYS_getpid); return 0; } --- pkg/csource/csource.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'pkg/csource/csource.go') diff --git a/pkg/csource/csource.go b/pkg/csource/csource.go index c8513286f..75b5a5e02 100644 --- a/pkg/csource/csource.go +++ b/pkg/csource/csource.go @@ -239,7 +239,12 @@ func (ctx *context) emitCall(w *bytes.Buffer, call prog.ExecCall, ci int, haveCo } fmt.Fprintf(w, "0") } - fmt.Fprintf(w, ");\n") + fmt.Fprintf(w, ");") + comment := ctx.target.AnnotateCall(call) + if len(comment) != 0 { + fmt.Fprintf(w, " /* %s */", comment) + } + fmt.Fprintf(w, "\n") if trace { cast := "" if !native && !strings.HasPrefix(callName, "syz_") { -- cgit mrf-deployment