diff options
| author | zeertzjq <zeertzjq@outlook.com> | 2023-12-02 10:10:25 +0800 |
|---|---|---|
| committer | zeertzjq <zeertzjq@outlook.com> | 2023-12-02 10:41:31 +0800 |
| commit | 9cc346119bee505e0be3827b35c573701a307001 (patch) | |
| tree | 90da4ca3281025b6dd94d02c03538b7d8ee2f234 /src/nvim | |
| parent | 01edcd6db85ab2abffa95bc4dce6cfb8de617bca (diff) | |
| download | rneovim-9cc346119bee505e0be3827b35c573701a307001.tar.gz rneovim-9cc346119bee505e0be3827b35c573701a307001.tar.bz2 rneovim-9cc346119bee505e0be3827b35c573701a307001.zip | |
vim-patch:9.0.2142: [security]: stack-buffer-overflow in option callback functions
Problem: [security]: stack-buffer-overflow in option callback functions
Solution: pass size of errbuf down the call stack, use snprintf()
instead of sprintf()
We pass the error buffer down to the option callback functions, but in
some parts of the code, we simply use sprintf(buf) to write into the error
buffer, which can overflow.
So let's pass down the length of the error buffer and use sprintf(buf, size)
instead.
Reported by @henices, thanks!
https://github.com/vim/vim/commit/b39b240c386a5a29241415541f1c99e2e6b8ce47
Co-authored-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src/nvim')
| -rw-r--r-- | src/nvim/option.c | 4 | ||||
| -rw-r--r-- | src/nvim/option_defs.h | 1 | ||||
| -rw-r--r-- | src/nvim/option_vars.h | 2 | ||||
| -rw-r--r-- | src/nvim/optionstr.c | 2 |
4 files changed, 6 insertions, 3 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c index 7a7cda2fa0..ba9d1262d4 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1455,7 +1455,7 @@ int do_set(char *arg, int opt_flags) } else { char *startarg = arg; // remember for error message const char *errmsg = NULL; - char errbuf[80]; + char errbuf[ERR_BUFLEN]; do_one_set_option(opt_flags, &arg, &did_show, errbuf, sizeof(errbuf), &errmsg); @@ -3845,7 +3845,7 @@ const char *set_option_value(const char *const name, const OptVal value, int opt int opt_idx = findoption(name); if (opt_idx < 0) { - snprintf(errbuf, IOSIZE, _(e_unknown_option2), name); + snprintf(errbuf, sizeof(errbuf), _(e_unknown_option2), name); return errbuf; } diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index b2e8081a08..6d0401f319 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -66,6 +66,7 @@ typedef struct { /// is parameterized, then the "os_errbuf" buffer is used to store the error /// message (when it is not NULL). char *os_errbuf; + /// length of the error buffer size_t os_errbuflen; void *os_win; diff --git a/src/nvim/option_vars.h b/src/nvim/option_vars.h index b0e9ff9434..66185940ca 100644 --- a/src/nvim/option_vars.h +++ b/src/nvim/option_vars.h @@ -938,6 +938,8 @@ enum { // Value for b_p_ul indicating the global value must be used. #define NO_LOCAL_UNDOLEVEL (-123456) +#define ERR_BUFLEN 80 + #define SB_MAX 100000 // Maximum 'scrollback' value. #define MAX_NUMBERWIDTH 20 // used for 'numberwidth' and 'statuscolumn' diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index 0a7d77e817..544524dd42 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -442,7 +442,7 @@ int check_signcolumn(win_T *wp) const char *check_stl_option(char *s) { int groupdepth = 0; - static char errbuf[80]; + static char errbuf[ERR_BUFLEN]; while (*s) { // Check for valid keys after % sequences |