Skip to content
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

make: bail out if there are spaces in the path #5221

Merged
merged 3 commits into from
Apr 20, 2016
Merged

make: bail out if there are spaces in the path #5221

merged 3 commits into from
Apr 20, 2016

Conversation

Kijewski
Copy link
Contributor

If we use rm -r(f) then we should make sure that we don't delete random directory trees because there was a whitespace in the path.

Related story: “In A UEFI World, "rm -rf /" Can Brick Your System”.

@Kijewski Kijewski added the Area: build system Area: Build system label Mar 31, 2016
@Kijewski Kijewski added this to the Release 2016.04 milestone Mar 31, 2016
@jnohlgard
Copy link
Member

Is checking them all at once robust?
Is there any combination of input environment variables which will result in 9 words in the test when a space is included somewhere, such as setting something to the empty string or a space or something else stupid?

@@ -42,6 +42,10 @@ BINDIRBASE := $(abspath $(BINDIRBASE))
BINDIR ?= $(BINDIRBASE)/$(BOARD)
BINDIR := $(abspath $(BINDIR))/

ifneq (9, $(words ${RIOTBASE} ${CCACHE_BASEDIR} ${RIOTCPU} ${RIOTBOARD} ${RIOTPROJECT} ${RIOTPKG} ${APPDIR} ${BINDIRBASE} ${BINDIR}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a substitution for each variable in case it is undefined or empty:

ifneq (9, $(words ${RIOTBASE}:-default ${CCACHE_BASEDIR}:-default ${RIOTCPU}:-default ${RIOTBOARD}:-default ${RIOTPROJECT}:-default ${RIOTPKG}:-default ${APPDIR}:-default ${BINDIRBASE}:-default ${BINDIR}:-default))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My logic was borken. Now I apply each variable individually to $(words) and test if any outcome is unequal 1.

@Kijewski
Copy link
Contributor Author

Kijewski commented Apr 5, 2016

@gebart, no my check was not rebust at all. Fixed.

Also I noticed a non-absolute BINDIR leads to messed up build. It is ensured now, too, that variables are absolute, and end with a slash if they need to.

@jnohlgard
Copy link
Member

If the paths have to end with a slash or no slash then it is a bug in the build system. Where does it fail if the path contains an extra slash in the middle? Normally /bin/ls and /bin//ls point to the same file, same as /bin/./ls as well. Additionally, abspath will filter away all extra slashes and relative directories. You could do an override MYDIR:=$(abspath ${MYDIR}) to always get a consistent state with regards to slashes

@Kijewski
Copy link
Contributor Author

Kijewski commented Apr 5, 2016

If you use BINDIR=../junk/folder make then everything is fine, as the makefile uses BINDIR := $(abspath $(BINDIR))/. But this does not work for make BINDIR=../junk/folder, here you'd need override … _= …. Should I rather use override than printing an error message?

@Kijewski
Copy link
Contributor Author

Kijewski commented Apr 5, 2016

Seems like override does not affect recursive "make"s. So this does not work.

@cgundogan
Copy link
Member

hmm, the former implementation was much less intrusive (:

@Kijewski
Copy link
Contributor Author

Kijewski commented Apr 5, 2016

Now it works. I think it's not even ugly. :)


GITCACHE:=$(RIOTBASE)/dist/tools/git/git-cache
# Path to the current directory relative to the git root
BUILDRELPATH ?= $(shell git rev-parse --show-prefix)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes it necessary to have a .git directory in our root, and to have git installed.
Why not just ${PWD#$RIOTBASE} ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only moved the line.

@Kijewski
Copy link
Contributor Author

Please review again.

@Kijewski Kijewski added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Apr 12, 2016
@cgundogan
Copy link
Member

doesn't seem to break anything for me. ACK please squash

@Kijewski Kijewski removed the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Apr 18, 2016
@kaspar030 kaspar030 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Apr 18, 2016
@Kijewski
Copy link
Contributor Author

Squashed

@kaspar030 kaspar030 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Apr 18, 2016
ifneq (, $(filter-out 1, $(foreach v,${__DIRECTORY_VARIABLES},$(words ${${v}}))))
$(info Aborting compilation for your safety.)
$(info Related variables = ${__DIRECTORY_VARIABLES})
$(error Make sure no path override is empty or contains spaces!)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this fail on many Windows systems?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are spaces in the path, yes, that's the point. :) Otherwise Windows' directory layout got smarter, e.g. $HOME is C:\Users$ID, Eigene Daten is actually $HOME/Documents. There should be no spaces in your common folders unless you put one in there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kijewski I am just wondering: would it be "safer" if this check is done after making all paths absolute below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would catch the unlikely case that (RIOTBASE != PWD) && !contains_space(RIOTBASE) && contains_space(PWD). Will change this evening.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change this evening.

@Kijewski it's now or never (for this release at least) (;

If we use `rm -r(f)` then we should make sure that we don't delete
random directory trees because there was a whitespace in the path.
@Kijewski
Copy link
Contributor Author

Addressed @cgundogan's comment, squashed directly.

@cgundogan
Copy link
Member

nice!

@cgundogan cgundogan added the Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch label Apr 20, 2016
@cgundogan
Copy link
Member

ACK and GO

@cgundogan cgundogan merged commit 8a85725 into RIOT-OS:master Apr 20, 2016
@cgundogan cgundogan removed the Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch label Apr 20, 2016
miri64 added a commit that referenced this pull request Apr 21, 2016
make: bail out if there are spaces in the path (backport of #5221)
@Kijewski Kijewski deleted the rm-rf-safe branch April 22, 2016 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: build system Area: Build system CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants