[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
@@ -67,6 +67,11 @@ touch "$NVM_DIR/versions/io.js/$IOJS_VERSION/bin/node"
|
||||
chmod +x "$NVM_DIR/versions/io.js/$IOJS_VERSION/bin/node"
|
||||
nvm_is_version_installed "iojs-$IOJS_VERSION" || die "nvm_is_version_installed iojs-$IOJS_VERSION should work via the fallback"
|
||||
|
||||
# a version that nvm_version_path rejects is never installed
|
||||
for BAD_VERSION in '..' 'v/../x' '../node/12.0.0' 'iojs-v/../x'; do
|
||||
! nvm_is_version_installed "$BAD_VERSION" || die "nvm_is_version_installed $BAD_VERSION should fail with a '..' path component"
|
||||
done
|
||||
|
||||
# the modern layout is found without shelling out to detect the OS
|
||||
FAST_VERSION='14.0.0'
|
||||
! nvm_is_version_installed "$FAST_VERSION" || die "nvm_is_version_installed $FAST_VERSION should fail before it is installed"
|
||||
@@ -92,5 +97,14 @@ nvm_get_os() {
|
||||
}
|
||||
check_version '13.0.0' 'node.exe'
|
||||
|
||||
# nvm_version_path's failure must be honored, not just its (usually empty) output,
|
||||
# which would otherwise turn the check into one for `/bin/node`
|
||||
nvm_version_path() {
|
||||
echo "$NODE_PATH/13.0.0"
|
||||
return 3
|
||||
}
|
||||
! nvm_is_version_installed 'v/../x' || die "nvm_is_version_installed must fail when nvm_version_path fails"
|
||||
unset -f nvm_version_path
|
||||
|
||||
|
||||
cleanup
|
||||
Reference in new issue
Block a user