Mercurial > vim
comparison src/message.c @ 26288:8e0cbe0d84ec v8.2.3675
patch 8.2.3675: using freed memory when vim_strsave() fails
Commit: https://github.com/vim/vim/commit/ba8c92687d53c91bbc20c867a49e0988819ea2d5
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Nov 25 14:43:18 2021 +0000
patch 8.2.3675: using freed memory when vim_strsave() fails
Problem: Using freed memory when vim_strsave() fails.
Solution: Clear "last_sourcing_name". Check for msg_source() called
recursively. (closes #8217)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 25 Nov 2021 15:45:04 +0100 |
parents | ae947ebb4038 |
children | fc859aea8cec |
comparison
equal
deleted
inserted
replaced
26287:6c01cf7bd288 | 26288:8e0cbe0d84ec |
---|---|
520 */ | 520 */ |
521 void | 521 void |
522 msg_source(int attr) | 522 msg_source(int attr) |
523 { | 523 { |
524 char_u *p; | 524 char_u *p; |
525 static int recursive = FALSE; | |
526 | |
527 // Bail out if something called here causes an error. | |
528 if (recursive) | |
529 return; | |
530 recursive = TRUE; | |
525 | 531 |
526 ++no_wait_return; | 532 ++no_wait_return; |
527 p = get_emsg_source(); | 533 p = get_emsg_source(); |
528 if (p != NULL) | 534 if (p != NULL) |
529 { | 535 { |
539 } | 545 } |
540 | 546 |
541 // remember the last sourcing name printed, also when it's empty | 547 // remember the last sourcing name printed, also when it's empty |
542 if (SOURCING_NAME == NULL || other_sourcing_name()) | 548 if (SOURCING_NAME == NULL || other_sourcing_name()) |
543 { | 549 { |
544 vim_free(last_sourcing_name); | 550 VIM_CLEAR(last_sourcing_name); |
545 if (SOURCING_NAME == NULL) | 551 if (SOURCING_NAME != NULL) |
546 last_sourcing_name = NULL; | |
547 else | |
548 last_sourcing_name = vim_strsave(SOURCING_NAME); | 552 last_sourcing_name = vim_strsave(SOURCING_NAME); |
549 } | 553 } |
550 --no_wait_return; | 554 --no_wait_return; |
555 | |
556 recursive = FALSE; | |
551 } | 557 } |
552 | 558 |
553 /* | 559 /* |
554 * Return TRUE if not giving error messages right now: | 560 * Return TRUE if not giving error messages right now: |
555 * If "emsg_off" is set: no error messages at the moment. | 561 * If "emsg_off" is set: no error messages at the moment. |