diff options
author | Ghjuvan Lacambre <code@lacamb.re> | 2023-05-28 16:04:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-28 16:04:54 +0200 |
commit | 5a3752889c5b7e18d1041eb873ca2fa9ceb814bd (patch) | |
tree | 07e0a62ee0abe2814d310565b5d71b3a613de85f /src | |
parent | d561830a5242a00545a320acb80be083dd590d05 (diff) | |
download | rneovim-5a3752889c5b7e18d1041eb873ca2fa9ceb814bd.tar.gz rneovim-5a3752889c5b7e18d1041eb873ca2fa9ceb814bd.tar.bz2 rneovim-5a3752889c5b7e18d1041eb873ca2fa9ceb814bd.zip |
fix(NVIM_APPNAME): show error message if $NVIM_APPNAME is invalid
Closes https://github.com/neovim/neovim/issues/23056.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/main.c | 5 | ||||
-rw-r--r-- | src/nvim/os/stdpaths.c | 13 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c index d4fbf8ce93..f27ebb2f67 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -250,6 +250,11 @@ int main(int argc, char **argv) argv0 = argv[0]; + if (!appname_is_valid()) { + os_errmsg("$NVIM_APPNAME is not a valid file name.\n"); + exit(1); + } + if (argc > 1 && STRICMP(argv[1], "-ll") == 0) { if (argc == 2) { print_mainerr(err_arg_missing, argv[1]); diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 8b62b9e895..53ddda22fa 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -69,6 +69,19 @@ const char *get_appname(void) return env_val; } +/// Ensure that APPNAME is valid. In particular, it cannot contain directory separators. +bool appname_is_valid(void) +{ + const char *appname = get_appname(); + const size_t appname_len = strlen(appname); + for (size_t i = 0; i < appname_len; i++) { + if (appname[i] == PATHSEP) { + return false; + } + } + return true; +} + /// Return XDG variable value /// /// @param[in] idx XDG variable to use. |