To: vim_dev@googlegroups.com Subject: Patch 9.0.1511 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1511 Problem: Crash when using wrong arg types to assert_match(). Solution: Check for NULL pointer. (closes #12349) Files: src/testing.c, src/testdir/test_assert.vim *** ../vim-9.0.1510/src/testing.c 2023-05-04 18:58:18.406209671 +0100 --- src/testing.c 2023-05-06 12:19:25.880160488 +0100 *************** *** 281,289 **** garray_T ga; char_u buf1[NUMBUFLEN]; char_u buf2[NUMBUFLEN]; - int called_emsg_before = called_emsg; - char_u *pat; - char_u *text; if (in_vim9script() && (check_for_string_arg(argvars, 0) == FAIL --- 281,286 ---- *************** *** 291,299 **** || check_for_opt_string_arg(argvars, 2) == FAIL)) return 1; ! pat = tv_get_string_buf_chk(&argvars[0], buf1); ! text = tv_get_string_buf_chk(&argvars[1], buf2); ! if (called_emsg == called_emsg_before && pattern_match(pat, text, FALSE) != (atype == ASSERT_MATCH)) { prepare_assert_error(&ga); --- 288,296 ---- || check_for_opt_string_arg(argvars, 2) == FAIL)) return 1; ! char_u *pat = tv_get_string_buf_chk(&argvars[0], buf1); ! char_u *text = tv_get_string_buf_chk(&argvars[1], buf2); ! if (pat != NULL && text != NULL && pattern_match(pat, text, FALSE) != (atype == ASSERT_MATCH)) { prepare_assert_error(&ga); *************** *** 420,443 **** { char_u buf1[NUMBUFLEN]; char_u buf2[NUMBUFLEN]; - int called_emsg_before = called_emsg; char_u *fname1 = tv_get_string_buf_chk(&argvars[0], buf1); char_u *fname2 = tv_get_string_buf_chk(&argvars[1], buf2); - garray_T ga; FILE *fd1; FILE *fd2; char line1[200]; char line2[200]; int lineidx = 0; ! if (called_emsg > called_emsg_before) return 0; IObuff[0] = NUL; fd1 = mch_fopen((char *)fname1, READBIN); if (fd1 == NULL) { ! vim_snprintf((char *)IObuff, IOSIZE, (char *)e_cant_read_file_str, fname1); } else { --- 417,439 ---- { char_u buf1[NUMBUFLEN]; char_u buf2[NUMBUFLEN]; char_u *fname1 = tv_get_string_buf_chk(&argvars[0], buf1); char_u *fname2 = tv_get_string_buf_chk(&argvars[1], buf2); FILE *fd1; FILE *fd2; char line1[200]; char line2[200]; int lineidx = 0; ! if (fname1 == NULL || fname2 == NULL) return 0; IObuff[0] = NUL; fd1 = mch_fopen((char *)fname1, READBIN); if (fd1 == NULL) { ! vim_snprintf((char *)IObuff, IOSIZE, (char *)e_cant_read_file_str, ! fname1); } else { *************** *** 445,451 **** if (fd2 == NULL) { fclose(fd1); ! vim_snprintf((char *)IObuff, IOSIZE, (char *)e_cant_read_file_str, fname2); } else { --- 441,448 ---- if (fd2 == NULL) { fclose(fd1); ! vim_snprintf((char *)IObuff, IOSIZE, (char *)e_cant_read_file_str, ! fname2); } else { *************** *** 498,505 **** --- 495,504 ---- fclose(fd2); } } + if (IObuff[0] != NUL) { + garray_T ga; prepare_assert_error(&ga); if (argvars[2].v_type != VAR_UNKNOWN) { *************** *** 528,533 **** --- 527,533 ---- ga_clear(&ga); return 1; } + return 0; } *** ../vim-9.0.1510/src/testdir/test_assert.vim 2023-05-04 18:58:18.410209481 +0100 --- src/testdir/test_assert.vim 2023-05-06 12:14:25.019915952 +0100 *************** *** 335,340 **** --- 335,357 ---- call remove(v:errors, 0) endfunc + func Test_assert_wrong_arg_emsg_off() + CheckFeature folding + + new + call setline(1, ['foo', 'bar']) + 1,2fold + + " This used to crash Vim + let &l:foldtext = 'assert_match({}, {})' + redraw! + + let &l:foldtext = 'assert_equalfile({}, {})' + redraw! + + bwipe! + endfunc + func Test_assert_fails_in_try_block() try call assert_equal(0, assert_fails('throw "error"')) *** ../vim-9.0.1510/src/version.c 2023-05-05 22:58:30.805061562 +0100 --- src/version.c 2023-05-06 12:16:10.219998526 +0100 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1511, /**/ -- The process for understanding customers primarily involves sitting around with other marketing people and talking about what you would to if you were dumb enough to be a customer. (Scott Adams - The Dilbert principle) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///