aboutsummaryrefslogtreecommitdiffstats
path: root/prog/prog.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2024-03-06 14:47:02 +0100
committerAleksandr Nogikh <nogikh@google.com>2024-03-13 10:31:21 +0000
commit20d042025bd8e1f91bb1fec20ae1509a08bfa4ef (patch)
treee8a3dcb48db65376fdf865480ca5d043f4c7bdcc /prog/prog.go
parent76713834e4ab721bc6265c89203ee171152cc017 (diff)
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.
Diffstat (limited to 'prog/prog.go')
-rw-r--r--prog/prog.go3
1 files changed, 3 insertions, 0 deletions
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)