gnodet commented on code in PR #1514: URL: https://github.com/apache/maven-mvnd/pull/1514#discussion_r4793004017
########## dist/src/main/distro/bin/mvnd-bash+zsh-completion.sh: ########## @@ -0,0 +1,409 @@ +# +# Copyright 2019 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Adapted from https://github.com/juven/maven-bash-completion/blob/master/bash_completion.bash by Juven Xu and others +# under Apache License Version 2.0 + +# Detect shell type +if [ -n "$ZSH_VERSION" ]; then + __MVND_SHELL="zsh" +elif [ -n "$BASH_VERSION" ]; then + __MVND_SHELL="bash" +else + __MVND_SHELL="unknown" +fi + +# Check if the current shell is zsh +__is_zsh() +{ + [ "$__MVND_SHELL" = "zsh" ] +} + +# ZSH-specific setup +if __is_zsh; then + # Enable bash compatibility Review Comment: **Important:** compinit -u bypasses security checks for insecure directories (world-writable or group-writable). Malicious completion scripts could be loaded from compromised directories. **Failure scenario:** /usr/local/share/zsh/site-functions is world-writable → attacker plants malicious completion → user sources this script → compinit -u loads malicious code without warning → arbitrary code execution **Fix:** Use 'compinit' without -u, or document why -u is needed and warn users to verify directory permissions ########## dist/src/main/distro/bin/mvnd-bash+zsh-completion.sh: ########## @@ -0,0 +1,409 @@ +# +# Copyright 2019 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Adapted from https://github.com/juven/maven-bash-completion/blob/master/bash_completion.bash by Juven Xu and others +# under Apache License Version 2.0 + +# Detect shell type +if [ -n "$ZSH_VERSION" ]; then + __MVND_SHELL="zsh" +elif [ -n "$BASH_VERSION" ]; then + __MVND_SHELL="bash" +else + __MVND_SHELL="unknown" +fi + +# Check if the current shell is zsh +__is_zsh() +{ + [ "$__MVND_SHELL" = "zsh" ] +} + +# ZSH-specific setup +if __is_zsh; then + # Enable bash compatibility + autoload -Uz compinit + compinit -u 2>/dev/null + + # Load bashcompinit for bash-style completions + autoload -Uz bashcompinit + bashcompinit + + # Set options for better compatibility + setopt NO_BEEP + setopt COMPLETE_IN_WORD + setopt ALWAYS_TO_END + + # Define COMP_WORDBREAKS if not set (bash compatibility) + [[ -z "$COMP_WORDBREAKS" ]] && COMP_WORDBREAKS=$' \t\n"\'><=;|&(:' +fi + +function_exists() +{ + if __is_zsh; then + # zsh uses 'typeset -f' or 'whence -f' to check function existence Review Comment: **Nit (optional):** Unquoted $1 in function_exists. While function names rarely contain spaces, unquoted variables can cause word splitting or glob expansion. **Failure scenario:** Caller passes function name containing * or ? → typeset -f $1 performs glob expansion → checks wrong functions or errors → function_exists returns wrong result → completion guards fail **Fix:** Quote both instances: 'typeset -f "$1"' (line 57) and 'declare -F "$1"' (line 60) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
