Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninitialized memory when running tests with valgrind: regmatch.rm_ic not initialized #8800

Closed
dpelle opened this issue Aug 26, 2021 · 0 comments

Comments

@dpelle
Copy link
Member

dpelle commented Aug 26, 2021

Describe the bug

Valgrind detects use of uninitialized memory when running vim tests.

To Reproduce

Build vim with valgrind run this test:

$ cd vim/src/tesdir
$ make test_breakindent

File valgrind.test_breakindent then contains:

==10483== Memcheck, a memory error detector
==10483== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==10483== Using Valgrind-3.17.0.GIT and LibVEX; rerun with -h for copyright info
==10483== Command: ../vim -f -u unix.vim -U NONE --noplugin --not-a-term -S runtest.vim test_breakindent.vim --cmd au\ SwapExists\ *\ let\ v:swapchoice\ =\ "e"
==10483== Parent PID: 10482
==10483== 
==10483== Conditional jump or move depends on uninitialised value(s)
==10483==    at 0x57A1A3: nfa_regmatch (regexp_nfa.c:6492)
==10483==    by 0x579145: nfa_regtry (regexp_nfa.c:7236)
==10483==    by 0x579145: nfa_regexec_both (regexp_nfa.c:7431)
==10483==    by 0x538598: vim_regexec_string (regexp.c:2799)
==10483==    by 0x4BD7AE: get_breakindent_win (indent.c:956)
==10483==    by 0x671C00: win_lbr_chartabsize (charset.c:1137)
==10483==    by 0x6715A2: win_linetabsize (charset.c:821)
==10483==    by 0x4E7613: plines_win_nofold (misc1.c:400)
==10483==    by 0x4E755E: plines_win_nofill (misc1.c:380)
==10483==    by 0x4F2494: comp_botline (move.c:83)
==10483==    by 0x4F0EEE: validate_botline_win (move.c:610)
==10483==    by 0x4F0EEE: validate_botline (move.c:600)
==10483==    by 0x4F0EEE: update_topline (move.c:316)
==10483==    by 0x4F2696: curs_columns (move.c:959)
==10483==    by 0x47C05C: ex_redraw (ex_docmd.c:8117)
==10483==    by 0x475D7E: do_one_cmd (ex_docmd.c:2610)
==10483==    by 0x475D7E: do_cmdline (ex_docmd.c:999)
==10483==    by 0x613C0B: call_user_func (userfunc.c:2699)
==10483==    by 0x613C0B: call_user_func_check (userfunc.c:2846)
==10483==    by 0x612791: call_func (userfunc.c:3336)
==10483==    by 0x6120D1: get_func_tv (userfunc.c:1707)
==10483==    by 0x619D09: ex_call (userfunc.c:4971)
==10483==    by 0x475D7E: do_one_cmd (ex_docmd.c:2610)
==10483==    by 0x475D7E: do_cmdline (ex_docmd.c:999)
==10483==    by 0x454BD5: ex_execute (eval.c:6247)
==10483==    by 0x475D7E: do_one_cmd (ex_docmd.c:2610)
==10483==    by 0x475D7E: do_cmdline (ex_docmd.c:999)
==10483==    by 0x613C0B: call_user_func (userfunc.c:2699)
==10483==    by 0x613C0B: call_user_func_check (userfunc.c:2846)
==10483==    by 0x612791: call_func (userfunc.c:3336)
==10483==    by 0x6120D1: get_func_tv (userfunc.c:1707)
==10483==    by 0x619D09: ex_call (userfunc.c:4971)
==10483==    by 0x475D7E: do_one_cmd (ex_docmd.c:2610)
==10483==    by 0x475D7E: do_cmdline (ex_docmd.c:999)
==10483==    by 0x5A2516: do_source (scriptfile.c:1406)
==10483==    by 0x5A1CA8: cmd_source (scriptfile.c:971)
==10483==    by 0x475D7E: do_one_cmd (ex_docmd.c:2610)
==10483==    by 0x475D7E: do_cmdline (ex_docmd.c:999)
==10483==    by 0x677DCC: exe_commands (main.c:3081)
==10483==    by 0x677DCC: vim_main2 (main.c:773)
==10483==    by 0x676F55: main (main.c:425)
==10483==  Uninitialised value was created by a stack allocation
==10483==    at 0x4BD5A0: get_breakindent_win (indent.c:906)
==10483== 
(more errors after that)

You need to add the valgrind --track-origins=yes option to see that the uninitialize memory comes from the stack of function get_breakindent_win.

The following patch avoids the valgrind error, but I'm not sure whether it's correct. At least it should give a clue as to how to properly fix it:

$ diff --git a/src/indent.c b/src/indent.c
index 99951c81b..6f4b2476d 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -949,6 +949,7 @@ get_breakindent_win(
     {
        regmatch_T          regmatch;
 
+       regmatch.rm_ic = FALSE;
        regmatch.regprog = vim_regcomp(curbuf->b_p_flp,
                                   RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT);
        if (regmatch.regprog != NULL)

Environment

  • Vim version 8.2.3377
  • OS: xubuntu-18.04.5
chrisbra pushed a commit to chrisbra/vim that referenced this issue Aug 30, 2021
Problem:    Using uninitialized memory.
Solution:   Initialize the rm_ic field. (Dominique Pellé, closes vim#8800)
seandewar added a commit to seandewar/neovim that referenced this issue Sep 6, 2021
Problem:    Using uninitialized memory.
Solution:   Initialize the rm_ic field. (Dominique Pellé, closes vim/vim#8800)
vim/vim@a918712
seandewar added a commit to seandewar/neovim that referenced this issue Sep 10, 2021
Problem:    Using uninitialized memory.
Solution:   Initialize the rm_ic field. (Dominique Pellé, closes vim/vim#8800)
vim/vim@a918712
seandewar added a commit to seandewar/neovim that referenced this issue Sep 10, 2021
Problem:    Using uninitialized memory.
Solution:   Initialize the rm_ic field. (Dominique Pellé, closes vim/vim#8800)
vim/vim@a918712
seandewar added a commit to seandewar/neovim that referenced this issue Sep 10, 2021
Problem:    Using uninitialized memory.
Solution:   Initialize the rm_ic field. (Dominique Pellé, closes vim/vim#8800)
vim/vim@a918712
lewis6991 pushed a commit to lewis6991/neovim that referenced this issue Dec 12, 2021
Problem:    Using uninitialized memory.
Solution:   Initialize the rm_ic field. (Dominique Pellé, closes vim/vim#8800)
vim/vim@a918712
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant