From 4097c8d7a8596ddbc9a9db7b7f39c5cbdb1bd742 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Wed, 6 Mar 2024 14:47:02 +0100 Subject: sys/linux: clone args before mutation Not cloning the argument results in replaceArg() replacing a union argument with itself, which may lead to inconsistent resource references. Add an assertion to detect such cases in the future. --- prog/prog.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'prog/prog.go') diff --git a/prog/prog.go b/prog/prog.go index f93293b64..da6f158bc 100644 --- a/prog/prog.go +++ b/prog/prog.go @@ -354,6 +354,9 @@ func (p *Prog) insertBefore(c *Call, calls []*Call) { // replaceArg replaces arg with arg1 in a program. func replaceArg(arg, arg1 Arg) { + if arg == arg1 { + panic("replacing an argument with itself") + } switch a := arg.(type) { case *ConstArg: *a = *arg1.(*ConstArg) -- cgit mrf-deployment