Debian Codegraph @

libexec/pyenv-version-file-read

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2 # Usage: pyenv version-file-read <file>
3 set -e
4 [scip-shell system . . `[`. -n "$PYENV_DEBUG" ] && set -x
5
6 VERSION_FILE="$1"
7
8 function is_version_safescip-shell shell shell-project 0.0.0 is_version_safe().() {
9 # As needed, check that the constructed path exists as a child path of PYENV_ROOT/versions
10 version="$1"
11 if [[ "$version" == ".." || "$version" == */* ]]; then
12 # Sanity check the value of version to prevent malicious path-traversal
13 (
14 cd "$PYENV_ROOT/versions/$version" &>/dev/nullscip-shell filesystem . . `/dev/null`. || exit 1
15 [[ "$PWD" == "$PYENV_ROOT/versions/"* ]]
16 )
17 return $?
18 else
19 return 0
20 fi
21 }
22
23 if [scip-shell system . . `[`. -s "$VERSION_FILE" ]; then
24 # Read the first non-whitespace word from the specified version file.
25 # Be careful not to load it whole in case there's something crazy in it.
26 IFS="$IFS"$'\r'
27 sep=
28 while read -n 1024 -r version _ || [[ $version ]]; do
29 if [[ -z "$version" || "$version" == \#* ]]; then
30 # Skip empty lines and comments
31 continue
32 elif ! is_version_safescip-shell shell shell-project 0.0.0 is_version_safe(). "$version"; then
33 # CVE-2022-35861 allowed arbitrary code execution in some contexts and is mitigated by is_version_safe.
34 echoscip-shell system . . echo. "pyenv: invalid version \`$version' ignored in \`$VERSION_FILE'" >&2
35 continue
36 fi
37 printfscip-shell system . . printf. "%s%s" "$sep" "$version"
38 sep=:
39 done <"$VERSION_FILE"
40 [[ $sep ]] && { echoscip-shell system . . echo.; exit; }
41 fi
42
43 exit 1