diff options
author | Kurtis Rader <krader@skepticism.us> | 2016-05-08 15:57:56 -0700 |
---|---|---|
committer | Kurtis Rader <krader@skepticism.us> | 2016-05-14 20:38:32 -0700 |
commit | 51468b764689e7d724a87e6c2b8cdb4e599a3604 (patch) | |
tree | 75fe13dbad791e0d143a3610bfe7ed7d0136ad38 /src/function.cpp | |
parent | ff1d651415a2752e82ec417294f9bdf8c234c10f (diff) |
add `function --shadow-builtin` flag
It's currently too easy for someone to bork their shell by doing something
like `function test; return 0; end`. That's obviously a silly, contrived,
example but the point is that novice users who learn about functions are
prone to do something like that without realizing it will bork the shell. Even
expert users who know about the `test` builtin might forget that, say, `pwd`
is a builtin.
This change adds a `--shadow-builtin` flag that must be specified to
indicate you know what you're doing.
Fixes #3000
Diffstat (limited to 'src/function.cpp')
-rw-r--r-- | src/function.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/function.cpp b/src/function.cpp index f717a16f..54559bee 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -141,7 +141,8 @@ function_info_t::function_info_t(const function_data_t &data, const wchar_t *fil named_arguments(data.named_arguments), inherit_vars(snapshot_vars(data.inherit_vars)), is_autoload(autoload), - shadows(data.shadows) {} + shadow_builtin(data.shadow_builtin), + shadow_scope(data.shadow_scope) {} function_info_t::function_info_t(const function_info_t &data, const wchar_t *filename, int def_offset, bool autoload) @@ -152,7 +153,8 @@ function_info_t::function_info_t(const function_info_t &data, const wchar_t *fil named_arguments(data.named_arguments), inherit_vars(data.inherit_vars), is_autoload(autoload), - shadows(data.shadows) {} + shadow_builtin(data.shadow_builtin), + shadow_scope(data.shadow_scope) {} void function_add(const function_data_t &data, const parser_t &parser, int definition_line_offset) { ASSERT_IS_MAIN_THREAD(); @@ -255,10 +257,16 @@ std::map<wcstring, env_var_t> function_get_inherit_vars(const wcstring &name) { return func ? func->inherit_vars : std::map<wcstring, env_var_t>(); } -int function_get_shadows(const wcstring &name) { +int function_get_shadow_builtin(const wcstring &name) { scoped_lock lock(functions_lock); const function_info_t *func = function_get(name); - return func ? func->shadows : false; + return func ? func->shadow_builtin : false; +} + +int function_get_shadow_scope(const wcstring &name) { + scoped_lock lock(functions_lock); + const function_info_t *func = function_get(name); + return func ? func->shadow_scope : false; } bool function_get_desc(const wcstring &name, wcstring *out_desc) { |