[Fix] nvm_ls_remote_index_tab, nvm_compare_checksum: also keep non-ASCII controls from the mirror off the terminal
Rejecting only ASCII control characters in the LTS codename still lets through a UTF-8 C1 control (like U+009B, a CSI) or a bidi override (like U+202E), which some terminals act on. A row is now kept only if its codename is `-`, empty, or alias-safe, which is the same shape the LTS alias step already requires, and every real codename has. BusyBox `tr` mishandles `-c` with a character class, so on Alpine the expected checksum printed as almost all `?`; an octal range in the C locale works in BusyBox, GNU, and BSD `tr`, and does not make BSD `tr` abort on invalid UTF-8.
This commit is contained in:
2 files changed
+12
-10
No files matched your search
@@ -2950,12 +2950,9 @@ nvm_ls_remote_index_tab() {
|
||||
return 3
|
||||
}
|
||||
# the mirror's index.tab is untrusted: skip the header, and any row whose version
|
||||
# is malformed or whose LTS codename carries control characters (which would reach
|
||||
# the terminal as escape sequences), before it is printed, stored as an LTS alias,
|
||||
# or matched against a pattern. The control characters are an octal range because
|
||||
# mawk 1.3.3 has no `[[:cntrl:]]`.
|
||||
# or LTS codename is malformed, before it is printed, stored as an LTS alias, or matched against a pattern
|
||||
VERSION_LIST="$(nvm_echo "${VERSION_LIST}" \
|
||||
| command awk -v prefix="${PREFIX}" 'NR > 1 && $1 ~ /^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$/ && $10 !~ /[\001-\037\177]/ { print prefix $0 }' \
|
||||
| command awk -v prefix="${PREFIX}" 'NR > 1 && $1 ~ /^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$/ && $10 ~ /^(-|[0-9A-Za-z][0-9A-Za-z._-]*)?$/ { print prefix $0 }' \
|
||||
)"
|
||||
local LTS_ALIAS
|
||||
local LTS_VERSION
|
||||
@@ -3136,8 +3133,8 @@ nvm_compare_checksum() {
|
||||
nvm_err 'Refusing to continue *without checksum verification*'
|
||||
return 1
|
||||
elif [ "${COMPUTED_SUM}" != "${CHECKSUM}" ] && [ "${COMPUTED_SUM}" != "\\${CHECKSUM}" ]; then
|
||||
# the expected checksum comes from the mirror, so show its control characters as `?`
|
||||
nvm_err "Checksums do not match: '${COMPUTED_SUM}' found, '$(command printf '%s' "${CHECKSUM}" | command tr -c '[:print:]' '?')' expected."
|
||||
# the expected checksum comes from the mirror, so show anything but printable ASCII as `?`
|
||||
nvm_err "Checksums do not match: '${COMPUTED_SUM}' found, '$(command printf '%s' "${CHECKSUM}" | LC_ALL=C command tr -c '\040-\176' '?')' expected."
|
||||
return 1
|
||||
fi
|
||||
nvm_err 'Checksums matched!'
|
||||
|
||||
Reference in new issue
Block a user