aboutsummaryrefslogtreecommitdiffstats
path: root/prog
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2024-03-06 14:47:02 +0100
committerAleksandr Nogikh <nogikh@google.com>2024-03-08 10:56:47 +0000
commit4097c8d7a8596ddbc9a9db7b7f39c5cbdb1bd742 (patch)
tree453b39ea237785218a551d24d6c474db317aa951 /prog
parent6387f6b7d487e2a77d753ad28c1074e39c17c3ca (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')
-rw-r--r--prog/clone.go4
-rw-r--r--prog/prog.go3
2 files changed, 7 insertions, 0 deletions
diff --git a/prog/clone.go b/prog/clone.go
index 029cf94c4..4523be0eb 100644
--- a/prog/clone.go
+++ b/prog/clone.go
@@ -39,6 +39,10 @@ func cloneCall(c *Call, newargs map[*ResultArg]*ResultArg) *Call {
return c1
}
+func CloneArg(arg Arg) Arg {
+ return clone(arg, nil)
+}
+
func clone(arg Arg, newargs map[*ResultArg]*ResultArg) Arg {
var arg1 Arg
switch a := arg.(type) {
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)