only obfuscate literals in packages to obfuscate

Add a regression test in gogarble.txt,
as that test is already set up with packages to not obfuscate.

This bug manifested in the form of a build failure for GOOS=plan9
with -literals turned on:

	[...]/os/file_plan9.go:151:12: invalid operation: cannot call non-function append (variable of type bool)

In this case, the "os" package is not to be obfuscated,
but we would still obfuscate its literals as per the bug.

But, since the package's identifiers were not obfuscated,
names like "append" were not replaced as per ea2e0bdf71,
meaning that the shadowing would still affect us.

Fixes #417.
pull/430/head
Daniel Martí 3 years ago
parent fceb19f6da
commit a144789910

@ -1227,7 +1227,9 @@ func (tf *transformer) recordType(t types.Type) {
// transformGo obfuscates the provided Go syntax file.
func (tf *transformer) transformGo(file *ast.File) *ast.File {
if opts.ObfuscateLiterals {
// Only obfuscate the literals here if the flag is on
// and if the package in question is to be obfuscated.
if opts.ObfuscateLiterals && curPkg.ToObfuscate {
file = literals.Obfuscate(file, tf.info, fset, tf.ignoreObjects)
}

@ -8,8 +8,12 @@ env GOPRIVATE=match-absolutely/nothing
! garble build -o=out ./standalone
stderr '^GOGARBLE="match-absolutely/nothing" does not match any packages to be built$'
# A build where just some packages are obfuscated.
env GOGARBLE=test/main/imported
garble build ./importer
garble -literals build -o=out ./importer
! binsubstr out 'some long string to obfuscate'
binsubstr out 'some long string to not obfuscate'
# Obfuscated packages which import non-obfuscated std packages.
# Some of the imported std packages use "import maps" due to vendoring,
@ -49,15 +53,18 @@ package main
func main() {}
-- importer/importer.go --
package importer
package main
import "test/main/imported"
var _ = imported.Name
func main() {
println(imported.LongString)
println("some long string to not obfuscate")
}
-- imported/imported.go --
package imported
var Name = "value"
var LongString = "some long string to obfuscate"
-- stdimporter/main.go --
package main

Loading…
Cancel
Save