Skip to content

Support paths with spaces in Makefile #1353

Closed

Description

@malexmave

🐞 Bug report

The Makefile does not support paths with spaces.

Describe the bug

If the repository is cloned to a location where the path leading to the repository contains spaces, Makefile commands can fail.

Try the following:

$ cd /tmp
$ git clone https://github.com/securecodebox/secureCodeBox "secure Code Box"
$ cd "secure Code Box"
$ make create-new-scanner NAME=test
find: /tmp/secure: No such file or directory
find: Code: No such file or directory
find: Box: No such file or directory
rm -rf /tmp/secure Code Box/scanners/test
cp -r /tmp/secure Code Box/.templates/new-scanner/ /tmp/secure Code Box/scanners/test
cp: Box/scanners/test is not a directory

Expected behavior

The Makefile should create a new scanner, instead of choking on the space and dying (or, even worse, copying stuff around randomly based on prefixes and polluting the file system of the user, or deleting their files, or...).

System (please complete the following information):

Should apply equally to Mac OS (tested), Linux (untested), Windows with WSL (tested)

Ideology

Yes, I know, spaces in folder names are considered an antipattern by some people. Still, in many situations (e.g., if you are using Windows with WSL and use your full name as username, and you drop your stuff in the "My Files" area of the system), you are pretty much guaranteed to encounter spaces. Instead of forcing developers to switch their workflows and where they store their code, we should just support this use case, if at all possible. And if we do not want to support this for whatever reason, we should ensure that the Makefile checks if there are spaces in the folder path, and refuse to perform operations that may break because of them, instead of bugging out and doing weird stuff that may or may not end up creating and deleting files in random places.

Activity

  1. moved this to Backlog in secureCodeBoxon Sep 13, 2022
  2. malexmave commented on Sep 13, 2022

    @malexmave
    MemberAuthor

    This seems to be a problem caused by the fix to #754 in commit eceb125 (edit: not caused by this directly, but probably related to it), where all quotes were removed from the Makefile. This breaks support for spaces in the paths (edit: actually, it doesn't), and it also breaks the sed call in the find -exec part of the Makefile, which will now return:

    make create-new-scanner NAME=ffuf
    rm -rf /tmp/secureCOdeBox/scanners/ffuf
    cp -r /tmp/secureCOdeBox/.templates/new-scanner/ /tmp/secureCOdeBox/scanners/ffuf
    find /tmp/secureCOdeBox/scanners/ffuf -type f ! -name tmp \
    		-exec sed -n s/new-scanner/ffuf/g;w /tmp/secureCOdeBox/scanners/ffuf/tmp {} \; \
    		-exec mv /tmp/secureCOdeBox/scanners/ffuf/tmp {} \;
    find: -exec: no terminating ";" or "+"
    11:13  up  3:23, 2 users, load averages: 2,10 2,20 2,11
    USER     TTY      FROM              LOGIN@  IDLE WHAT
    mv /tmp/secureCOdeBox/scanners/ffuf/templates/new-scanner-parse-definition.yaml \
    		/tmp/secureCOdeBox/scanners/ffuf/templates/ffuf-parse-definition.yaml
    mv /tmp/secureCOdeBox/scanners/ffuf/templates/new-scanner-scan-type.yaml \
    		/tmp/secureCOdeBox/scanners/ffuf/templates/ffuf-scan-type.yaml
    

    Reverting the commit and adding the quotes back in does not fix the original issue, but it at least fixes the find -exec sed call.

    I think we need some test cases for our Makefiles...

  3. moved this from Backlog to In Progress in secureCodeBoxon Sep 13, 2022
  4. Weltraumschaf commented on Sep 13, 2022

    @Weltraumschaf
    Member

    The important part missed by me is:

    So, if the shell expects and can interpret a quoted string, then you should use quotes. Where the shell doesn't expect or won't correctly interpret a quoted string, you should not use quotes. (SO)

  5. added 2 commits that reference this issue on Sep 13, 2022
  6. Weltraumschaf commented on Sep 13, 2022

    @Weltraumschaf
    Member

    Houston, we have a problem!

    We have this "sophsticated" find:

    PACKAGE_JSON_LIST				:= $(shell find "$(PROJECT_DIR)" \( \
                                       		-name .git -o \
                                       		-name .github -o \
                                       		-name .idea -o \
                                       		-name .reuse -o \
                                       		-name .vagrant -o \
                                       		-name .vscode -o \
                                       		-name bin -o \
                                       		-name docs -o \
                                       		-name LICENSES -o \
                                       		-name coverage -o \
                                       		-name dist -o \
                                       		-name node_modules -o \
                                       		-name target \) \
                                       		-prune \
                                       		-false \
                                       		-o -type f \
                                       		-iname package.json)

    To find all NPM packages. This results in a list of paths separated by spaces. Later we loop over them with shell for loop, which treats any whitespcae for word split. First approach is to use while read which splits only on newline. But the paths in the list are splitted by spaces...

  7. added 2 commits that reference this issue on Sep 14, 2022
  8. Weltraumschaf commented on Sep 14, 2022

    @Weltraumschaf
    Member

    First fixes: #1357

    But IMHO this is a major problem.

  9. added 2 commits that reference this issue on Sep 14, 2022
  10. 288 remaining items

  11. added 15 commits that reference this issue on Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions