diff options
author | Devon H. O'Dell <devon.odell@gmail.com> | 2010-01-13 16:48:14 -0800 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2010-01-13 16:48:14 -0800 |
commit | e8afb6d87f76668ce4b4b560d89e4ecc2b7d974f (patch) | |
tree | 455c9a825827545e2375f2f5e41896a07b658b80 | |
parent | c6336155f1718bd0485be8800d6cebedfe920073 (diff) | |
download | go-e8afb6d87f76668ce4b4b560d89e4ecc2b7d974f.tar.gz go-e8afb6d87f76668ce4b4b560d89e4ecc2b7d974f.zip |
cgo: Only allow numeric / string / character type constants for references
to #defined things.
Fixes #520.
R=rsc, rsaarelm
CC=golang-dev
https://golang.org/cl/186138
-rw-r--r-- | src/cmd/cgo/gcc.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index 4f65a1afb7..c525b492aa 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -48,7 +48,13 @@ func (p *Prog) loadDebugInfo() { val = strings.TrimSpace(line[tabIndex:]) } - defines[key] = val + // Only allow string, character, and numeric constants. Ignoring #defines for + // symbols allows those symbols to be referenced in Go, as they will be + // translated by gcc later. + _, err := strconv.Atoi(string(val[0])) + if err == nil || val[0] == '\'' || val[0] == '"' { + defines[key] = val + } } // Construct a slice of unique names from p.Crefs. |