Skip to content

Regression in 1.8.10: Segfault in arduino-builder with -dump-prefs if no sketch is specified #341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
obra opened this issue Sep 24, 2019 · 4 comments
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@obra
Copy link

obra commented Sep 24, 2019

[tl;dr: In 1.8.10, something changed in arduino-builder such that -dump-prefs no longer works without a sketch and -build-path specified. On top of that, there's a segfault when trying to abspath....something if a -build-path is provided, but no sketch is provided.]

Hi folks,

We've been seeing some weird behavior with 1.8.10. It manifested at first as

   fork/exec {runtime.tools.ctags.path}/ctags: no such file or directory

As I dug in, I discovered that the deeper issue was that arduino-builder was segfaulting when I ran arduino-builder -dump-prefs with a -build-path without a sketch:

$ /usr/local/arduino-1.8.10/arduino-builder -hardware /usr/local/arduino-1.8.10/hardware  -tools /usr/local/arduino-1.8.10/hardware/tools -fqbn arduino:avr:leonardo   -build-path /tmp/  -dump-prefs 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x5346a7]

goroutine 1 [running]:
github.com/arduino/go-paths-helper.(*Path).Abs(0x0, 0xc000021400, 0x0, 0x0)
	/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/go-paths-helper/paths.go:139 +0x27
github.com/arduino/arduino-cli/legacy/builder.(*ContainerSetupHardwareToolsLibsSketchAndProps).Run(0xfa4300, 0xc000021400, 0xfa4300, 0x40c3c8)
	/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/container_setup.go:67 +0x34e
github.com/arduino/arduino-cli/legacy/builder.runCommands(0xc000021400, 0xc00018fe00, 0x2, 0x2, 0x42b001, 0x8, 0xc000069df8)
	/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/builder.go:210 +0xdf
github.com/arduino/arduino-cli/legacy/builder.(*ParseHardwareAndDumpBuildProperties).Run(0xc000069e70, 0xc000021400, 0xfa41f0, 0x0)
	/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/builder.go:198 +0xcc
github.com/arduino/arduino-cli/legacy/builder.RunParseHardwareAndDumpBuildProperties(...)
	/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/builder.go:231
main.main()
	/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-builder/main.go:388 +0x8b1

```

# Everything's great with 1.8.9, even run against 1.8.10's libraries and config:

```
$ /usr/local/arduino-1.8.9/arduino-builder -fqbn arduino:avr:leonardo -hardware /usr/local/arduino-1.8.10/hardware/ -tools /usr/local/arduino-1.8.10/tools-builder/ -dump-prefs -warnings all -trace -debug-level 999

Ts: 1569351226 - Running: GenerateBuildPathIfMissing
Setting build path to /tmp/arduino-sketch-D41D8CD98F00B204E9800998ECF8427E
Ts: 1569351226 - Running: ContainerSetupHardwareToolsLibsSketchAndProps
Ts: 1569351226 - Running: AddAdditionalEntriesToContext
Ts: 1569351226 - Running: FailIfBuildPathEqualsSketchPath
Ts: 1569351226 - Running: HardwareLoader
Ts: 1569351226 - Running: PlatformKeysRewriteLoader
Ts: 1569351226 - Running: RewriteHardwareKeys
Ts: 1569351226 - Running: ToolsLoader
Ts: 1569351226 - Running: TargetBoardResolver
Ts: 1569351226 - Running: AddBuildBoardPropertyIfMissing
Ts: 1569351226 - Running: LibrariesLoader
Ts: 1569351226 - Running: SketchLoader
Ts: 1569351226 - Running: SetupBuildProperties
Ts: 1569351226 - Running: LoadVIDPIDSpecificProperties
Ts: 1569351226 - Running: SetCustomBuildProperties
Ts: 1569351226 - Running: AddMissingBuildPropertiesFromParentPlatformTxtFiles
Ts: 1569351226 - Running: DumpBuildProperties
_id=leonardo
archive_file_path={build.path}/{archive_file}
bootloader.extended_fuses=0xcb
bootloader.file=caterina/Caterina-Leonardo.hex
```

# 1.8.10 complains that there's no sketch, even if one is defined:

```
$ /usr/local/arduino-1.8.10/arduino-builder -fqbn arduino:avr:leonardo -hardware /usr/local/arduino-1.8.10/hardware/ -tools /usr/local/arduino-1.8.10/tools-builder/ -dump-prefs -warnings all -trace -debug-level 999 Model01-Firmware.ino
stat : no such file or directory
```

# Nightly does the same:

```
$ /usr/local/arduino-nightly/arduino-builder -fqbn arduino:avr:leonardo -hardware /usr/local/arduino-1.8.10/hardware/ -tools /usr/local/arduino-1.8.10/tools-builder/ -dump-prefs -warnings all -trace -debug-level 999 
stat : no such file or directory
```

#   #337 PARTIALLY fixes things, but only if given a sketch as an argument:

```

$ /tmp/linux64/arduino-builder -fqbn arduino:avr:leonardo -hardware /usr/local/arduino-1.8.10/hardware/ -tools /usr/local/arduino-1.8.10/tools-builder/ -dump-prefs -warnings all -trace -debug-level 999 Model01-Firmware.ino

/tmp/linux64/arduino-builder -fqbn arduino:avr:leonardo -hardware /usr/local/arduino-1.8.10/hardware/ -tools /usr/local/arduino-1.8.10/tools-builder/ -dump-prefs -warnings all -trace -debug-level 999 Model01-Firmware.ino 
Ts: 1569351539 - Running: ContainerSetupHardwareToolsLibsSketchAndProps
Ts: 1569351539 - Running: AddAdditionalEntriesToContext
Ts: 1569351539 - Running: FailIfBuildPathEqualsSketchPath
Ts: 1569351539 - Running: HardwareLoader
INFO[0000] Loading hardware from: /usr/local/arduino-1.8.10/hardware/ 
INFO[0000] Loading package arduino from: /usr/local/arduino-1.8.10/hardware/arduino 
INFO[0000] Loaded platform                               platform="arduino:[email protected]"
INFO[0000] Excluding directory: /usr/local/arduino-1.8.10/hardware/tools 
Ts: 1569351539 - Running: PlatformKeysRewriteLoader
Ts: 1569351539 - Running: RewriteHardwareKeys
Ts: 1569351539 - Running: TargetBoardResolver
Ts: 1569351539 - Running: ToolsLoader
INFO[0000] Loading tools from bundle dir: /usr/local/arduino-1.8.10/tools-builder/ 
INFO[0000] Loading tools from dir: /usr/local/arduino-1.8.10/tools-builder/ 
INFO[0000] Loaded tool                                   tool=":[email protected]"
INFO[0000] Loaded tool                                   tool=":[email protected]"
INFO[0000] Searching tools required for board arduino:avr:leonardo 
INFO[0000] Required tool                                 tool="arduino:[email protected]"
INFO[0000] Required tool                                 tool="arduino:[email protected]"
INFO[0000] Required tool                                 tool="arduino:[email protected]"
Ts: 1569351539 - Running: AddBuildBoardPropertyIfMissing
Ts: 1569351539 - Running: LibrariesLoader
INFO[0000] Adding libraries dir                          dir=/usr/local/arduino-1.8.10/hardware/arduino/avr/libraries location=platform
Ts: 1569351539 - Running: SetupBuildProperties
Ts: 1569351539 - Running: LoadVIDPIDSpecificProperties
Ts: 1569351539 - Running: SetCustomBuildProperties
Ts: 1569351539 - Running: AddMissingBuildPropertiesFromParentPlatformTxtFiles
Ts: 1569351539 - Running: DumpBuildProperties
_id=leonardo
archive_file_path={build.path}/{archive_file}
bootloader.extended_fuses=0xcb
bootloader.file=caterina/Caterina-Leonardo.hex
bootloader.high_fuses=0xd8
bootloader.lock_bits=0x2F
bootloader.low_fuses=0xff
bootloader.tool=avrdude
[...]

With #337 and no sketch as an argument, I'm getting segfaults as the builder tries to abspath an empty string

/tmp/linux64/arduino-builder -fqbn arduino:avr:leonardo -hardware /usr/local/arduino-1.8.10/hardware/ -tools /usr/local/arduino-1.8.10/tools-builder/ -dump-prefs -warnings all -trace -debug-level 999 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x84e855]

goroutine 1 [running]:
github.com/arduino/go-paths-helper.(*Path).String(...)
	/home/jenkins/go/pkg/mod/github.com/arduino/[email protected]/paths.go:467
github.com/arduino/arduino-cli/legacy/builder.(*ParseHardwareAndDumpBuildProperties).Run(0xc000095e70, 0xc00016d880, 0xc0001735c0, 0x0)
	/home/jenkins/go/pkg/mod/github.com/arduino/[email protected]/legacy/builder/builder.go:189 +0xf5
github.com/arduino/arduino-cli/legacy/builder.RunParseHardwareAndDumpBuildProperties(...)
	/home/jenkins/go/pkg/mod/github.com/arduino/[email protected]/legacy/builder/builder.go:231
main.main()
	/home/jenkins/workspace/arduino-builder-pr-builder/main.go:389 +0x837
@cmaglie
Copy link
Member

cmaglie commented Sep 24, 2019

Thanks for the detailed bug report! I will give a look tomorrow and report back here.

@cmaglie
Copy link
Member

cmaglie commented Sep 25, 2019

@obra may you test the build here #342 (comment) ?

@obra
Copy link
Author

obra commented Sep 25, 2019

@cmaglie thanks for the super-quick turnaround. That does indeed seem to solve the problem :)

@cmaglie
Copy link
Member

cmaglie commented Sep 26, 2019

Fixed by #342

@cmaglie cmaglie closed this as completed Sep 26, 2019
@rsora rsora added regression type: imperfection Perceived defect in any part of project labels Sep 22, 2021
@per1234 per1234 added conclusion: resolved Issue was resolved topic: code Related to content of the project itself labels Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

4 participants