From d9ffc81421c7dcf20d88106c5dca34ec35cb610a Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 5 Oct 2021 11:09:48 +0200 Subject: pkg/compiler: fix infinite recursion in template instantiation Fix a bug found by OSS-Fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=17240 We handled the case of infinite recursion in templates but only if the full type name matches precisely (A -> B -> A). In this case the name constantly changes due to different template arguments. Per se this is a not an error (and we have real cases that use this, e.g. when an nlattr_t contains nested nlattr_t's), but it's an error if it recurses infinitely. Restrict recursion on the same template to 10 levels. --- pkg/compiler/compiler_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'pkg/compiler/compiler_test.go') diff --git a/pkg/compiler/compiler_test.go b/pkg/compiler/compiler_test.go index 131270939..8045bf608 100644 --- a/pkg/compiler/compiler_test.go +++ b/pkg/compiler/compiler_test.go @@ -135,6 +135,15 @@ func TestData(t *testing.T) { func TestFuzz(t *testing.T) { t.Parallel() for _, data := range []string{ + ` +type p b[L] +type b[L]{ + e b[3:L] + e b[2:L] + e b[1[L]] + k b[H] + k b[Q] +}`, "d~^gB̉`i\u007f?\xb0.", "da[", "define\x98define(define\x98define\x98define\x98define\x98define)define\tdefin", -- cgit mrf-deployment