From c755bd03586dd1845bc720e25b5059b216b70afa Mon Sep 17 00:00:00 2001 From: axel Date: Fri, 21 Apr 2006 04:29:44 +1000 Subject: [PATCH] Only allow real directories in PATH, CDPATH, etc. If user tries to use ':' instead of arrays, give a friendly pointer on how to use arrays darcs-hash:20060420182944-ac50b-fbb5dc63c2a4d3fe3bde92ad7699b1cad972dd0f.gz --- builtin_set.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/builtin_set.c b/builtin_set.c index ff33da4a9..9c655309a 100644 --- a/builtin_set.c +++ b/builtin_set.c @@ -26,12 +26,16 @@ Functions used for implementing the set builtin. #include "parser.h" #include "translate.h" +#define BUILTIN_SET_PATH_ERROR L"%ls: Could not add component %ls to %ls.\n" +#define BUILTIN_SET_PATH_HINT L"%ls: Did you mean 'set %ls $%ls %ls'?\n" + /** Call env_set. On error, print a description of the problem to stderr. */ static void my_env_set( const wchar_t *key, const wchar_t *val, int scope ) { + switch( env_set( key, val, scope | ENV_USER ) ) { case ENV_PERM: @@ -265,6 +269,17 @@ static void print_variables(int include_values, int esc, int scope) al_destroy(&names); } +static int is_path_variable( const wchar_t *env ) +{ + return contains_str( env, + L"PATH", + L"CDPATH", + L"fish_function_path", + L"fish_completion_path", + (void *)0 ); +} + + /** The set builtin. Creates, updates and erases environment variables and environemnt variable arrays. */ @@ -478,6 +493,80 @@ int builtin_set( wchar_t **argv ) al_push(&values, argv[woptind++]); } + if( is_path_variable( dest ) ) + { + int i; + int error = 0; + + for( i=0; i