@@ -77,9 +77,6 @@ static const struct woption long_options[] = {
7777#define BUILTIN_SET_UVAR_ERR \
7878 _ (L" %ls: Universal variable '%ls' is shadowed by the global variable of the same name.\n " )
7979
80- // Test if the specified variable should be subject to path validation.
81- static int is_path_variable(const wcstring &env) { return env == L" PATH" || env == L" CDPATH" ; }
82-
8380static int parse_cmd_opts(set_cmd_opts_t &opts, int *optind, // !OCLINT(high ncss method)
8481 int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
8582 const wchar_t *cmd = argv[0 ];
@@ -247,64 +244,6 @@ static int check_global_scope_exists(const wchar_t *cmd, const set_cmd_opts_t &o
247244 return STATUS_CMD_OK;
248245}
249246
250- // Validate the given path `list`. If there are any entries referring to invalid directories which
251- // contain a colon, then complain. Return true if any path element was valid, false if not.
252- static bool validate_path_warning_on_colons (const wchar_t *cmd,
253- const wcstring &key, // !OCLINT(npath complexity)
254- const wcstring_list_t &list, io_streams_t &streams,
255- const environment_t &vars) {
256- // Always allow setting an empty value.
257- if (list.empty ()) return true ;
258-
259- bool any_success = false ;
260-
261- // Don't bother validating (or complaining about) values that are already present. When
262- // determining already-present values, use ENV_DEFAULT instead of the passed-in scope because
263- // in:
264- //
265- // set -l PATH stuff $PATH
266- //
267- // where we are temporarily shadowing a variable, we want to compare against the shadowed value,
268- // not the (missing) local value. Also don't bother to complain about relative paths, which
269- // don't start with /.
270- const auto existing_variable = vars.get (key, ENV_DEFAULT);
271- const wcstring_list_t &existing_values =
272- existing_variable ? existing_variable->as_list () : wcstring_list_t {};
273-
274- for (const wcstring &dir : list) {
275- if (!string_prefixes_string (L" /" , dir) || contains (existing_values, dir)) {
276- any_success = true ;
277- continue ;
278- }
279-
280- const wchar_t *colon = std::wcschr (dir.c_str (), L' :' );
281- bool looks_like_colon_sep = colon && colon[1 ];
282- if (!looks_like_colon_sep && any_success) {
283- // Once we have one valid entry, skip the remaining ones unless we might warn.
284- continue ;
285- }
286- struct stat buff;
287- bool valid = true ;
288- if (wstat (dir, &buff) == -1 ) {
289- valid = false ;
290- } else if (!S_ISDIR (buff.st_mode )) {
291- errno = ENOTDIR;
292- valid = false ;
293- } else if (waccess (dir, X_OK) == -1 ) {
294- valid = false ;
295- }
296- if (valid) {
297- any_success = true ;
298- } else if (looks_like_colon_sep) {
299- streams.err .append_format (BUILTIN_SET_PATH_ERROR, cmd, key.c_str (), dir.c_str (),
300- std::strerror (errno));
301- streams.err .append_format (BUILTIN_SET_PATH_HINT, cmd, key.c_str (), key.c_str (),
302- std::wcschr (dir.c_str (), L' :' ) + 1 );
303- }
304- }
305- return any_success;
306- }
307-
308247static void handle_env_return (int retval, const wchar_t *cmd, const wcstring &key,
309248 io_streams_t &streams) {
310249 switch (retval) {
@@ -344,10 +283,6 @@ static void handle_env_return(int retval, const wchar_t *cmd, const wcstring &ke
344283static int env_set_reporting_errors (const wchar_t *cmd, const wcstring &key, int scope,
345284 wcstring_list_t list, io_streams_t &streams, env_stack_t &vars,
346285 std::vector<event_t > *evts) {
347- if (is_path_variable (key) && !validate_path_warning_on_colons (cmd, key, list, streams, vars)) {
348- return STATUS_CMD_ERROR;
349- }
350-
351286 int retval = vars.set (key, scope | ENV_USER, std::move (list), evts);
352287 handle_env_return (retval, cmd, key, streams);
353288
0 commit comments