Skip to content

Commit da7aa86

Browse files
cmd/go: in cgoflags, permit -DX1, prohibit -Wp,-D,opt
Restrict -D and -U to ASCII C identifiers, but do permit trailing digits. When using -Wp, prohibit commas in -D values. Change-Id: Ibfc4dfdd6e6c258e131448e7682610c44eee9492 Reviewed-on: https://go-review.googlesource.com/c/go/+/267277 Trust: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent ecd7b7e commit da7aa86

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/cmd/go/internal/work/security.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ import (
4242
var re = lazyregexp.New
4343

4444
var validCompilerFlags = []*lazyregexp.Regexp{
45-
re(`-D([A-Za-z_].*)`),
46-
re(`-U([A-Za-z_]*)`),
45+
re(`-D([A-Za-z_][A-Za-z0-9_]*)(=[^@\-]*)?`),
46+
re(`-U([A-Za-z_][A-Za-z0-9_]*)`),
4747
re(`-F([^@\-].*)`),
4848
re(`-I([^@\-].*)`),
4949
re(`-O`),
5050
re(`-O([^@\-].*)`),
5151
re(`-W`),
5252
re(`-W([^@,]+)`), // -Wall but not -Wa,-foo.
5353
re(`-Wa,-mbig-obj`),
54-
re(`-Wp,-D([A-Za-z_].*)`),
55-
re(`-Wp,-U([A-Za-z_]*)`),
54+
re(`-Wp,-D([A-Za-z_][A-Za-z0-9_]*)(=[^@,\-]*)?`),
55+
re(`-Wp,-U([A-Za-z_][A-Za-z0-9_]*)`),
5656
re(`-ansi`),
5757
re(`-f(no-)?asynchronous-unwind-tables`),
5858
re(`-f(no-)?blocks`),

src/cmd/go/internal/work/security_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var goodCompilerFlags = [][]string{
1313
{"-DFOO"},
1414
{"-Dfoo=bar"},
1515
{"-Ufoo"},
16+
{"-Ufoo1"},
1617
{"-F/Qt"},
1718
{"-I/"},
1819
{"-I/etc/passwd"},
@@ -24,6 +25,8 @@ var goodCompilerFlags = [][]string{
2425
{"-Wall"},
2526
{"-Wp,-Dfoo=bar"},
2627
{"-Wp,-Ufoo"},
28+
{"-Wp,-Dfoo1"},
29+
{"-Wp,-Ufoo1"},
2730
{"-fobjc-arc"},
2831
{"-fno-objc-arc"},
2932
{"-fomit-frame-pointer"},
@@ -80,6 +83,8 @@ var badCompilerFlags = [][]string{
8083
{"-O@1"},
8184
{"-Wa,-foo"},
8285
{"-W@foo"},
86+
{"-Wp,-DX,-D@X"},
87+
{"-Wp,-UX,-U@X"},
8388
{"-g@gdb"},
8489
{"-g-gdb"},
8590
{"-march=@dawn"},

0 commit comments

Comments
 (0)