8000 Fixed path-relativization error when traversing different partitions by cmaglie · Pull Request #658 · arduino/arduino-cli · GitHub
[go: up one dir, main page]

Skip to content

Fixed path-relativization error when traversing different partitions #658

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

Merged
merged 1 commit into from
Apr 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fixed path-relativization error when traversing different partitions
It happened on MacOSX, but I do not exclude it may happen in other OS
too: when building some large sketch for Arduino Due, the system libsam_xxx.a
library is transformed to relative path, in particular the path

/Users/cmaglie/Library/Arduino15/packages/arduino/hardware/sam/1.6.12/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a

is made relative to the build folder

/var/folder/x8/ttjf_wrd63823894128467832/T/arduino_build_988374/

but since both paths resides in different partitions the result is:

../../../../../../Users/cmaglie/Library/Arduino15/packages/arduino/hardware/sam/1.6.12/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a

so it traverse from /var/..../arduino_buil_988374 to the root and descend back into /Users

This is bad for two reasons:

1) the resulting "relative" path is longer than the original "absolute"
path, defeating the purpose of the transformation.

2) for some weird reason gcc is unable to find the libsam file using the
relative path. It seems that when running inside /var/... it cannot "escape" to
/Users/...

This patch avoid the situation above by adding a check for the presence
of ".." in the resulting path (basically avoiding path relativization
outside of the build folder) and by checking that the resulting path is
shorter than the original absolute path.
  • Loading branch information
cmaglie committed Apr 14, 2020
commit 8e10983e148279f0b525d6f46906474c475fcc00
2 changes: 1 addition & 1 deletion legacy/builder/utils/utils.go
< 4FEF td class="blob-code blob-code-context js-file-line"> if _, err := os.Stat(part); !os.IsNotExist(err) {
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func PrepareCommandFilteredArgs(pattern string, filter argFilterFunc, logger i18
if relativePath != "" {
tmp, err := filepath.Rel(relativePath, part)
if err == nil {
if err == nil && !strings.Contains(tmp, "..") && len(tmp) < len(part) {
part = tmp
}
}
Expand Down
0