Skip to content

Commit c4fbaee

Browse files
gregory-mJay Conrod
authored and
Jay Conrod
committed
cmd/go: allow -I= and -I$SYSROOT in cgo CFLAGS
Current checkFlags() didn't allow any not safe charactars in arguments. In GCC "=" in arguments will be replaced with sysroot prefix, and used by users to work with different SDK versions. This CL allow to use "=" and $SYSROOT with -I argument. Fixes #34449 Change-Id: I3d8b2b9d13251e454ea18e9d34a94b87c373c7b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/196783 Run-TryBot: Jay Conrod <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 2dfff36 commit c4fbaee

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,15 @@ Args:
280280
continue Args
281281
}
282282

283+
// Permit -I= /path, -I $SYSROOT.
284+
if i+1 < len(list) && arg == "-I" {
285+
if (strings.HasPrefix(list[i+1], "=") || strings.HasPrefix(list[i+1], "$SYSROOT")) &&
286+
load.SafeArg(list[i+1][1:]) {
287+
i++
288+
continue Args
289+
}
290+
}
291+
283292
if i+1 < len(list) {
284293
return fmt.Errorf("invalid flag in %s: %s %s (see https://golang.org/s/invalidflag)", source, arg, list[i+1])
285294
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ var goodCompilerFlags = [][]string{
5656
{"-I", "."},
5757
{"-I", "/etc/passwd"},
5858
{"-I", "世界"},
59+
{"-I", "=/usr/include/libxml2"},
60+
{"-I", "dir"},
61+
{"-I", "$SYSROOT/dir"},
5962
{"-framework", "Chocolate"},
6063
{"-x", "c"},
6164
{"-v"},
@@ -83,6 +86,7 @@ var badCompilerFlags = [][]string{
8386
{"-D", "-foo"},
8487
{"-I", "@foo"},
8588
{"-I", "-foo"},
89+
{"-I", "=@obj"},
8690
{"-framework", "-Caffeine"},
8791
{"-framework", "@Home"},
8892
{"-x", "--c"},

0 commit comments

Comments
 (0)