nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 97fa42c82bc26b23bec36dccd845c6c5311f0652
parent ccabaac5a035f4caf352bc0b422071129595b666
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Wed, 31 Aug 2022 16:20:29 +0200

memory: avoid a leak when a string bind specifies an unknown menu

(It is a harmless leak, but LeakSanitizer is loud when it complains.)

After having determined that there is a menu name, first check that
it is valid, before processing the string or the function name.

This fixes https://savannah.gnu.org/bugs/?62991.

Problem existed since version 2.9.4, since string binds were introduced.

Diffstat:
Msrc/rcfile.c | 12++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/rcfile.c b/src/rcfile.c @@ -787,6 +787,12 @@ void parse_binding(char *ptr, bool dobind) goto free_things; } + menu = name_to_menu(menuptr); + if (menu < 1) { + jot_error(N_("Cannot map name \"%s\" to a menu"), menuptr); + goto free_things; + } + if (dobind) { /* If the thing to bind starts with a double quote, it is a string, * otherwise it is the name of a function. */ @@ -806,12 +812,6 @@ void parse_binding(char *ptr, bool dobind) } } - menu = name_to_menu(menuptr); - if (menu < 1) { - jot_error(N_("Cannot map name \"%s\" to a menu"), menuptr); - goto free_things; - } - /* Wipe the given shortcut from the given menu. */ for (keystruct *s = sclist; s != NULL; s = s->next) if ((s->menus & menu) && s->keycode == keycode)