]> Cypherpunks repositories - gostls13.git/commitdiff
cgo: Only allow numeric / string / character type constants for references
authorDevon H. O'Dell <devon.odell@gmail.com>
Thu, 14 Jan 2010 00:48:14 +0000 (16:48 -0800)
committerRuss Cox <rsc@golang.org>
Thu, 14 Jan 2010 00:48:14 +0000 (16:48 -0800)
to #defined things.

Fixes #520.

R=rsc, rsaarelm
CC=golang-dev
https://golang.org/cl/186138

src/cmd/cgo/gcc.go

index 4f65a1afb7295cc2b3c7df7e58d2b822f3ef4be3..c525b492aaff3aa9b649267858a4b4671cb5cec2 100644 (file)
@@ -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.