mirror of
				https://github.com/nvm-sh/nvm.git
				synced 2025-10-31 10:15:53 +08:00 
			
		
		
		
	[Fix] fix directory traversal when workdir path is not readable
This commit is contained in:
		
				
					committed by
					
						 Jordan Harband
						Jordan Harband
					
				
			
			
				
	
			
			
			
						parent
						
							44e1d9c911
						
					
				
				
					commit
					0d9b5c2a00
				
			
							
								
								
									
										4
									
								
								nvm.sh
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								nvm.sh
									
									
									
									
									
								
							| @@ -418,7 +418,7 @@ nvm_tree_contains_path() { | |||||||
| nvm_find_project_dir() { | nvm_find_project_dir() { | ||||||
|   local path_ |   local path_ | ||||||
|   path_="${PWD}" |   path_="${PWD}" | ||||||
|   while [ "${path_}" != "" ] && [ ! -f "${path_}/package.json" ] && [ ! -d "${path_}/node_modules" ]; do |   while [ "${path_}" != "" ] && [ "${path_}" != '.' ] && [ ! -f "${path_}/package.json" ] && [ ! -d "${path_}/node_modules" ]; do | ||||||
|     path_=${path_%/*} |     path_=${path_%/*} | ||||||
|   done |   done | ||||||
|   nvm_echo "${path_}" |   nvm_echo "${path_}" | ||||||
| @@ -428,7 +428,7 @@ nvm_find_project_dir() { | |||||||
| nvm_find_up() { | nvm_find_up() { | ||||||
|   local path_ |   local path_ | ||||||
|   path_="${PWD}" |   path_="${PWD}" | ||||||
|   while [ "${path_}" != "" ] && [ ! -f "${path_}/${1-}" ]; do |   while [ "${path_}" != "" ] && [ "${path_}" != '.' ] && [ ! -f "${path_}/${1-}" ]; do | ||||||
|     path_=${path_%/*} |     path_=${path_%/*} | ||||||
|   done |   done | ||||||
|   nvm_echo "${path_}" |   nvm_echo "${path_}" | ||||||
|   | |||||||
| @@ -31,3 +31,6 @@ ACTUAL="$(PWD=$TEST_DIR/no-nesting-n_m nvm_find_project_dir)" | |||||||
|  |  | ||||||
| ACTUAL="$(PWD=$TEST_DIR/no-nesting-pkg nvm_find_project_dir)" | ACTUAL="$(PWD=$TEST_DIR/no-nesting-pkg nvm_find_project_dir)" | ||||||
| [ "${ACTUAL}" = "$TEST_DIR/no-nesting-pkg" ] || die "no-nesting-pkg: got ${ACTUAL}" | [ "${ACTUAL}" = "$TEST_DIR/no-nesting-pkg" ] || die "no-nesting-pkg: got ${ACTUAL}" | ||||||
|  |  | ||||||
|  | ACTUAL="$(PWD="." nvm_find_project_dir)" | ||||||
|  | [ "${ACTUAL}" = "." ] || die "insufficient permissions for pwd: got ${ACTUAL}" | ||||||
|   | |||||||
| @@ -21,5 +21,6 @@ TEST_DIR="$PWD" | |||||||
| [ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up" ] || die "failed to find 2 dirs up" | [ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up" ] || die "failed to find 2 dirs up" | ||||||
| [ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b/c nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up/a/b/c" ] || die "failed to find in current dir" | [ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b/c nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up/a/b/c" ] || die "failed to find in current dir" | ||||||
| [ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b/c/d nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up/a/b/c" ] || die "failed to find 1 level up from current dir" | [ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b/c/d nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up/a/b/c" ] || die "failed to find 1 level up from current dir" | ||||||
|  | [ "~$(PWD="." nvm_find_up 'test')" = "~." ] || die "failed to handle '.' output from pwd" | ||||||
|  |  | ||||||
| cleanup | cleanup | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user