`[ "$1" -eq "$1" ]` accepts more than a natural number: a leading `+`, and leading or trailing whitespace, and in ksh it evaluates its operands as arithmetic expressions, so words like `install` and expressions like `1+1` or `V=1` pass too. Values with any non-digit character are now rejected before that test. The sunos and aix branches of `nvm_get_make_jobs` count cores with `wc -l`, which on those platforms pads the count with whitespace, so that count is now stripped of whitespace before it is checked Discovered by Anthropic's OSS Scanner, as bug ANT-2026-SYLQD6PZ; the scanner correctly classified it as not a vulnerability.
25 lines
988 B
Bash
Executable File
25 lines
988 B
Bash
Executable File
#!/bin/sh
|
|
|
|
die () { echo "$@" ; exit 1; }
|
|
|
|
: nvm.sh
|
|
\. ../../../nvm.sh
|
|
|
|
! nvm_is_natural_num || die 'no args is not false'
|
|
! nvm_is_natural_num '' || die 'empty string is not false'
|
|
! nvm_is_natural_num a || die 'a is not false'
|
|
! nvm_is_natural_num -1 || 'negative number is not false'
|
|
! nvm_is_natural_num --1 || 'double negative number is not false'
|
|
! nvm_is_natural_num 1.2 || 'decimal number is not false'
|
|
! nvm_is_natural_num 0 || die 'zero is not false'
|
|
! nvm_is_natural_num +3 || die 'explicitly positive number is not false'
|
|
! nvm_is_natural_num ' 3' || die 'leading whitespace is not false'
|
|
! nvm_is_natural_num '3 ' || die 'trailing whitespace is not false'
|
|
! nvm_is_natural_num install || die 'a word is not false'
|
|
! nvm_is_natural_num V=1 || die 'an assignment is not false'
|
|
! nvm_is_natural_num 1+1 || die 'an expression is not false'
|
|
|
|
nvm_is_natural_num 1 || die '1 is not true'
|
|
nvm_is_natural_num 2 || die '2 is not true'
|
|
nvm_is_natural_num 1234 || die '1234 is not true'
|