aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGregory Anders <greg@gpanders.com>2022-11-05 19:30:48 -0600
committerGregory Anders <greg@gpanders.com>2022-11-17 08:23:41 -0700
commit294910a1ffd11bea0081c2b92632628ef0462eb1 (patch)
treefa2636155cf69bcced5b89f3b3ffdf8498398d89 /src
parentf1922e78a1df1b1d32779769432fb5586edf5fbb (diff)
downloadrneovim-294910a1ffd11bea0081c2b92632628ef0462eb1.tar.gz
rneovim-294910a1ffd11bea0081c2b92632628ef0462eb1.tar.bz2
rneovim-294910a1ffd11bea0081c2b92632628ef0462eb1.zip
feat(exrc): use vim.secure.read() for 'exrc' option
Diffstat (limited to 'src')
-rw-r--r--src/nvim/lua/executor.c24
-rw-r--r--src/nvim/main.c12
-rw-r--r--src/nvim/testdir/test_startup.vim1
3 files changed, 35 insertions, 2 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index 79cc3ed112..43a3b12a98 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -2193,3 +2193,27 @@ plain:
kv_printf(str, "<Lua %d>", ref);
return str.items;
}
+
+char *nlua_read_secure(const char *path)
+{
+ lua_State *const lstate = global_lstate;
+ lua_getglobal(lstate, "vim");
+ lua_getfield(lstate, -1, "secure");
+ lua_getfield(lstate, -1, "read");
+ lua_pushstring(lstate, path);
+ lua_call(lstate, 1, 1);
+
+ size_t len = 0;
+ const char *contents = lua_tolstring(lstate, -1, &len);
+ char *buf = NULL;
+ if (contents != NULL) {
+ // Add one to include trailing null byte
+ buf = xcalloc(len + 1, sizeof(char));
+ memcpy(buf, contents, len + 1);
+ }
+
+ // Pop return value, "vim", and "secure"
+ lua_pop(lstate, 3);
+
+ return buf;
+}
diff --git a/src/nvim/main.c b/src/nvim/main.c
index d8570f49eb..e8c1c98c38 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -2002,7 +2002,11 @@ static void source_startup_scripts(const mparm_T *const parmp)
#endif
secure = p_secure;
- if (do_source(VIMRC_FILE, true, DOSO_VIMRC) == FAIL) {
+ char *str = nlua_read_secure(VIMRC_FILE);
+ if (str != NULL) {
+ do_source_str(str, VIMRC_FILE);
+ xfree(str);
+ } else {
#if defined(UNIX)
// if ".exrc" is not owned by user set 'secure' mode
if (!os_file_owned(EXRC_FILE)) {
@@ -2011,7 +2015,11 @@ static void source_startup_scripts(const mparm_T *const parmp)
secure = 0;
}
#endif
- (void)do_source(EXRC_FILE, false, DOSO_NONE);
+ str = nlua_read_secure(EXRC_FILE);
+ if (str != NULL) {
+ do_source_str(str, EXRC_FILE);
+ xfree(str);
+ }
}
}
if (secure == 2) {
diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim
index f9f7c5b492..42467c5508 100644
--- a/src/nvim/testdir/test_startup.vim
+++ b/src/nvim/testdir/test_startup.vim
@@ -1024,6 +1024,7 @@ endfunc
" Test for using the 'exrc' option
func Test_exrc()
+ throw 'Skipped: Nvim requires user input for the exrc option'
let after =<< trim [CODE]
call assert_equal(1, &exrc)
call assert_equal(1, &secure)