From bfdfc2603c187447d32ecbc8b5a378df53af5734 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sat, 21 Dec 2019 14:51:54 +0100 Subject: prog: don't fail decoding on non-default out args We get them in cross-compilation test where an out const arg has different values in different archs. No reason to fail deserialization in that case, replace with default arg instead. --- prog/encoding.go | 9 ++++++++- prog/encoding_test.go | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'prog') diff --git a/prog/encoding.go b/prog/encoding.go index 1da491186..e4f762756 100644 --- a/prog/encoding.go +++ b/prog/encoding.go @@ -382,7 +382,14 @@ func (p *parser) parseArgInt(typ Type) (Arg, error) { return nil, fmt.Errorf("wrong arg value '%v': %v", val, err) } switch typ.(type) { - case *ConstType, *IntType, *FlagsType, *ProcType, *LenType, *CsumType: + case *ConstType, *IntType, *FlagsType, *ProcType, *CsumType: + arg := Arg(MakeConstArg(typ, v)) + if typ.Dir() == DirOut && !typ.isDefaultArg(arg) { + p.strictFailf("out arg %v has non-default value: %v", typ, v) + arg = typ.DefaultArg() + } + return arg, nil + case *LenType: return MakeConstArg(typ, v), nil case *ResourceType: return MakeResultArg(typ, nil, v), nil diff --git a/prog/encoding_test.go b/prog/encoding_test.go index f828123db..ba7fe3329 100644 --- a/prog/encoding_test.go +++ b/prog/encoding_test.go @@ -267,6 +267,11 @@ func TestDeserialize(t *testing.T) { input: `test$blob0(&AUTO="3031000a0d7022273a01")`, output: `test$blob0(&(0x7f0000000040)="3031000a0d7022273a01")`, }, + { + input: `test$out_const(&(0x7f0000000000)=0x2)`, + output: `test$out_const(&(0x7f0000000000))`, + strictErr: regexp.MustCompile(`out arg const\[1, const\] has non-default value: 2`), + }, } buf := make([]byte, ExecBufferSize) for _, test := range tests { -- cgit mrf-deployment