Setting a large line or column number using a //line directive can cause
integer overflow even in small source files.

Limit line and column numbers in //line directives to 2^30-1, which
is small enough to avoid int32 overflow on all reasonbly-sized files.

Fixes CVE-2023-24537
Fixes #59273
For #59180

Signed-off-by: Vivek Kumbhar <vkumb...@mvista.com>
---
 meta/recipes-devtools/go/go-1.14.inc          |  1 +
 .../go/go-1.14/CVE-2023-24537.patch           | 76 +++++++++++++++++++
 2 files changed, 77 insertions(+)
 create mode 100644 meta/recipes-devtools/go/go-1.14/CVE-2023-24537.patch

diff --git a/meta/recipes-devtools/go/go-1.14.inc 
b/meta/recipes-devtools/go/go-1.14.inc
index 8df9d62612..c3201da8b2 100644
--- a/meta/recipes-devtools/go/go-1.14.inc
+++ b/meta/recipes-devtools/go/go-1.14.inc
@@ -55,6 +55,7 @@ SRC_URI += "\
     file://CVE-2022-41723.patch \
     file://CVE-2022-41722-1.patch \
     file://CVE-2022-41722-2.patch \
+    file://CVE-2023-24537.patch \
 "
 
 SRC_URI_append_libc-musl = " 
file://0009-ld-replace-glibc-dynamic-linker-with-musl.patch"
diff --git a/meta/recipes-devtools/go/go-1.14/CVE-2023-24537.patch 
b/meta/recipes-devtools/go/go-1.14/CVE-2023-24537.patch
new file mode 100644
index 0000000000..e04b717fc1
--- /dev/null
+++ b/meta/recipes-devtools/go/go-1.14/CVE-2023-24537.patch
@@ -0,0 +1,76 @@
+From bf8c7c575c8a552d9d79deb29e80854dc88528d0 Mon Sep 17 00:00:00 2001
+From: Damien Neil <dn...@google.com>
+Date: Mon, 20 Mar 2023 10:43:19 -0700
+Subject: [PATCH] [release-branch.go1.20] mime/multipart: limit parsed mime
+ message sizes
+
+Reviewed-on: 
https://team-review.git.corp.google.com/c/golang/go-private/+/1802456
+Reviewed-by: Julie Qiu <julie...@google.com>
+Reviewed-by: Roland Shoemaker <bracew...@google.com>
+Run-TryBot: Damien Neil <dn...@google.com>
+Reviewed-on: 
https://team-review.git.corp.google.com/c/golang/go-private/+/1802611
+Reviewed-by: Damien Neil <dn...@google.com>
+Change-Id: Ifdfa192d54f722d781a4d8c5f35b5fb72d122168
+Reviewed-on: https://go-review.googlesource.com/c/go/+/481986
+Reviewed-by: Matthew Dempsky <mdemp...@google.com>
+TryBot-Result: Gopher Robot <go...@golang.org>
+Run-TryBot: Michael Knyszek <mknys...@google.com>
+Auto-Submit: Michael Knyszek <mknys...@google.com>
+
+Upstream-Status: Backport 
[https://github.com/golang/go/commit/126a1d02da82f93ede7ce0bd8d3c51ef627f2104]
+CVE: CVE-2023-24537
+Signed-off-by: Vivek Kumbhar <vkumb...@mvista.com>
+---
+ src/go/parser/parser_test.go | 16 ++++++++++++++++
+ src/go/scanner/scanner.go    |  5 ++++-
+ 2 files changed, 20 insertions(+), 1 deletion(-)
+
+diff --git a/src/go/parser/parser_test.go b/src/go/parser/parser_test.go
+index 37a6a2b..714557c 100644
+--- a/src/go/parser/parser_test.go
++++ b/src/go/parser/parser_test.go
+@@ -738,3 +738,19 @@ func TestScopeDepthLimit(t *testing.T) {
+               }
+       }
+ }
++
++// TestIssue59180 tests that line number overflow doesn't cause an infinite 
loop.
++func TestIssue59180(t *testing.T) {
++      testcases := []string{
++              "package p\n//line :9223372036854775806\n\n//",
++              "package p\n//line :1:9223372036854775806\n\n//",
++              "package p\n//line file:9223372036854775806\n\n//",
++      }
++
++      for _, src := range testcases {
++              _, err := ParseFile(token.NewFileSet(), "", src, ParseComments)
++              if err == nil {
++                      t.Errorf("ParseFile(%s) succeeded unexpectedly", src)
++              }
++      }
++}
+diff --git a/src/go/scanner/scanner.go b/src/go/scanner/scanner.go
+index 00fe2dc..3159d25 100644
+--- a/src/go/scanner/scanner.go
++++ b/src/go/scanner/scanner.go
+@@ -246,13 +246,16 @@ func (s *Scanner) updateLineInfo(next, offs int, text 
[]byte) {
+               return
+       }
+ 
++      // Put a cap on the maximum size of line and column numbers.
++      // 30 bits allows for some additional space before wrapping an int32.
++      const maxLineCol = 1<<30 - 1
+       var line, col int
+       i2, n2, ok2 := trailingDigits(text[:i-1])
+       if ok2 {
+               //line filename:line:col
+               i, i2 = i2, i
+               line, col = n2, n
+-              if col == 0 {
++              if col == 0 || col > maxLineCol {
+                       s.error(offs+i2, "invalid column number: 
"+string(text[i2:]))
+                       return
+               }
+-- 
+2.25.1
+
-- 
2.25.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#180271): 
https://lists.openembedded.org/g/openembedded-core/message/180271
Mute This Topic: https://lists.openembedded.org/mt/98405168/21656
Group Owner: openembedded-core+ow...@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to