-
Notifications
You must be signed in to change notification settings - Fork 119
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
devclean.sh
demonstrates very unsafe directory removal behavior
#1073
Comments
Just pinging this high-priority issue after more than two months, can we get someone to work on this? I can not emphasize enough that this script should not be used by anyone in its current state, nevermind recommended in the users guide as a way to solve unexpected build problems! |
@MichaelLueken May I open a PR to remove the script and the related documentation? It's easy enough to remove the documentation, but I figured a developer would make a decision to remove or revise the script. However, it seems like if we remove it, anyone who has an issue with that could fairly easily restore and update it. In the meantime, it seems prudent to just remove the problem until someone is interested in doing that. |
@gspetro-NOAA My concern with removing the script is that @natalie-perlin has noted that this feature was a stakeholder request. While it is most prudent to directly address this issue (opening a PR to remove the script and associated documentation), removing it to add it back in is a waste of resources. @natalie-perlin - would you be able to clean up the |
If it's actively dangerous, I'd assume that is decidedly NOT what a stakeholder would want. Removing it to protect user data seems like a higher priority than being able to resurrect a safer option that likely doesn't look like this script at all. |
The script is only dangerous if the user explicitly points to directories outside of their local I can certainly agree with @mkavulich that removal of user input for If this isn't enough, then @gspetro-NOAA, please feel free to remove the |
Let me try to address the concerns of the script, and add any checks that may mitigate the risks. This is script is especially needed for new users who start exploring the code, and usually go through several build issues. Including more documentation on how to do it by hand is always an option, and it could be done in addition to the script, too. |
@mkavulich @MichaelLueken It could be included in my PR-1089, or made as a separate PR. Please feel free to comment!
|
Updated a #1089, added a modified devbuild.sh with safety checks |
Adding a link to comments on the issue: |
Expected behavior
Forced, recursive removal of directories via bash scripts (
rm -rf
) should be handled very carefully. Any potential mishandling of input, whether it be from unexpected behavior of wildcards, command-line typos, undefined variables, or even intentional malfeasance, can result in very destructive results when therm -rf
command is used.Current behavior
The devclean.sh has several instances of
rm -rf
:[[ -d ${BUILD_DIR} ]] && rm -rf ${BUILD_DIR} && printf '%s\n' "rm -rf ${BUILD_DIR}"
[[ -d "${dir}" ]] && rm -rfv ${dir}
for sub in ${submodules[@]}; do [[ -d "${sub}" ]] && ( rm -rf ${sub} && printf '%s\n' "rm -rf ${sub}" ); done
rm -rf ${SRW_DIR}/conda_loc
rm -rf ${CONDA_DIR}
The first and last of these include the final boss of bad UNIX practices: they run
rm -rf
on a variable from a command-line argument that is not checked for existence prior to being used. It is also not invoked in quotes, so any wildcards will pass straight through.This is extremely unsafe behavior and should be eliminated ASAP
Machines affected
All
Steps To Reproduce
DO NOT TRY TO REPRODUCE THIS. Unless you like loss of data.
Detailed Description of Fix
rm -rf
commands should be handled with the caution of a lethal weapon. When they are necessary, they must be crafted very carefully, with explicit checks on the arguments to ensure that they 1. exist, and 2. can only correspond to expected results.My preferred solution? Delete this script forever and replace it with proper documentation on starting a clean build. All the script does is remove directories, and this is a responsibility that should be handed to users, not handled opaquely by bash scripts.
At the very minimum, if we are to keep this script, it should be restricted to only removing directories within the current tree. The ability to specify custom directory locations (specifically, the
--install-dir
,--build-dir
,--bin-dir
, and--conda-dir
arguments) is unsafe and unnecessary.Additional Information
Lest you think my description of this problem is over-dramatic, here is a real-world example from a much more widely used software package: ValveSoftware/steam-for-linux#3671
The text was updated successfully, but these errors were encountered: