[Fix] nvm_is_version_installed: fail when nvm_version_path fails
Since 072622c7, `nvm_version_path` rejects a version with a `..` path component, printing nothing and returning 3.
`nvm_is_version_installed` ignored that status and appended `/bin/node` to the empty output,
so for such a version (eg, `v/../x` in an `.nvmrc`)
it checked `/bin/node`,
and reported the version as installed whenever a system node lived there.
`nvm use` then put `/bin` in place of the active version on `PATH`,
and `nvm which` printed `/bin/node`.
Propagate `nvm_version_path`'s failure,
so such a version is never installed
Discovered by Anthropic's OSS Scanner, as bug ANT-2026-O1QONH45; the scanner correctly classified it as not a vulnerability.
This commit is contained in:
2 files changed
+17
-1
No files matched your search
@@ -273,7 +273,9 @@ nvm_is_version_installed() {
|
||||
if [ "_$(nvm_get_os)" = '_win' ]; then
|
||||
NVM_NODE_BINARY='node.exe'
|
||||
fi
|
||||
if [ -x "$(nvm_version_path "$1" 2>/dev/null)/bin/${NVM_NODE_BINARY}" ]; then
|
||||
local VERSION_PATH
|
||||
VERSION_PATH="$(nvm_version_path "$1" 2>/dev/null)" || return 1
|
||||
if [ -x "${VERSION_PATH}/bin/${NVM_NODE_BINARY}" ]; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
|
||||
Reference in new issue
Block a user