diff options
author | Devon H. O'Dell <devon.odell@gmail.com> | 2010-01-13 16:48:14 -0800 |
---|---|---|
committer | Devon H. O'Dell <devon.odell@gmail.com> | 2010-01-13 16:48:14 -0800 |
commit | 55799c919b9c20cd82a9d79180b2e184656ff848 (patch) | |
tree | 13e130c4006c4c3ce7168492369524ca446cfeab | |
parent | ce9f15e767409c645ad6f220c83c5260fda6d3c1 (diff) | |
download | golang-55799c919b9c20cd82a9d79180b2e184656ff848.tar.gz |
cgo: Only allow numeric / string / character type constants for references
to #defined things.
Fixes issue 520.
R=rsc, rsaarelm
CC=golang-dev
http://codereview.appspot.com/186138
Committer: Russ Cox <rsc@golang.org>
-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 4f65a1afb..c525b492a 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. |