diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-07-23 16:46:09 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-07-23 17:13:55 +0200 |
| commit | 70c104a18f3d409bc6dde950b50258d3d280d99b (patch) | |
| tree | f04031861627a08784d525296deba6f16c9d12e6 | |
| parent | 340ea5301c27db4a3678f13acc430e04706a0cc6 (diff) | |
pkg/compiler: fix crash on fmt[flags]
Flags with only 1 value 0 are transformed to ConstType.
Fmt did not expect that.
Fixes #1965
| -rw-r--r-- | pkg/compiler/testdata/all.txt | 3 | ||||
| -rw-r--r-- | pkg/compiler/types.go | 6 | ||||
| -rw-r--r-- | sys/test/exec.txt | 6 | ||||
| -rw-r--r-- | sys/test/test/fmt | 4 |
4 files changed, 19 insertions, 0 deletions
diff --git a/pkg/compiler/testdata/all.txt b/pkg/compiler/testdata/all.txt index f5f3f1070..b9e144d73 100644 --- a/pkg/compiler/testdata/all.txt +++ b/pkg/compiler/testdata/all.txt @@ -294,7 +294,10 @@ foo_fmt2(a ptr[in, fmt[oct, len[b]]], b ptr[in, array[int8]]) foo_fmt3(a ptr[in, fmt[dec, proc[10, 20]]]) foo_fmt4(a ptr[in, fmt[dec, r0]]) foo_fmt5(a ptr[in, struct$fmt0]) +foo_fmt6(a ptr[in, fmt[dec, flags[flags_with_one_value]]]) struct$fmt0 { f0 fmt[dec, int8] } + +flags_with_one_value = 0 diff --git a/pkg/compiler/types.go b/pkg/compiler/types.go index 122c4a9d4..3c22038f8 100644 --- a/pkg/compiler/types.go +++ b/pkg/compiler/types.go @@ -761,6 +761,12 @@ var typeFmt = &typeDesc{ t.ArgFormat = format t.TypeSize = size t.TypeAlign = 1 + case *prog.ConstType: + // We don't allow fmt[const] directly, but flags with only 1 value + // are transformed to ConstType. + t.ArgFormat = format + t.TypeSize = size + t.TypeAlign = 1 default: panic(fmt.Sprintf("unexpected type: %#v", typ)) } diff --git a/sys/test/exec.txt b/sys/test/exec.txt index 6ad985838..bb293e1d0 100644 --- a/sys/test/exec.txt +++ b/sys/test/exec.txt @@ -41,8 +41,14 @@ compare_data [ blob array[int8] arr16be array[int16be] nla array[compare_nla] + fmt0 fmt[oct, int32] + fmt1 fmt[dec, int32] + fmt2 fmt[hex, int32] + fmt3 fmt[dec, flags[flags_with_one_value]] ] [varlen] +flags_with_one_value = 0 + compare_nla [ a0 nlattr[0xaa, int8] a1 nlattr[0xbb, int16] diff --git a/sys/test/test/fmt b/sys/test/test/fmt new file mode 100644 index 000000000..41f584dc9 --- /dev/null +++ b/sys/test/test/fmt @@ -0,0 +1,4 @@ +syz_compare(&AUTO='00000000000000000000123', 0x17, &AUTO=@fmt0=0x53, AUTO) +syz_compare(&AUTO='00000000000000000083', 0x14, &AUTO=@fmt1=0x53, AUTO) +syz_compare(&AUTO='0x0000000000000053', 0x12, &AUTO=@fmt2=0x53, AUTO) +syz_compare(&AUTO='00000000000000000000', 0x14, &AUTO=@fmt3=AUTO, AUTO) |
