To: vim_dev@googlegroups.com Subject: Patch 7.4.1918 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.1918 Problem: Not enough testing for parsing viminfo lines. Solution: Add test with viminfo lines in bad syntax. Fix memory leak. Files: src/ex_cmds.c, src/ex_getln.c, src/testdir/test_viminfo.vim *** ../vim-7.4.1917/src/ex_cmds.c 2016-06-11 14:47:34.488604982 +0200 --- src/ex_cmds.c 2016-06-11 15:15:11.906675743 +0200 *************** *** 2589,2601 **** ++p; len = getdigits(&p); buf = alloc((int)(len + 1)); p = buf; for (todo = len; todo > 0; todo -= n) { if (viminfo_readline(virp) || virp->vir_line[0] != '|' || virp->vir_line[1] != '<') /* file was truncated or garbled */ ! return 0; /* Get length of text, excluding |< and NL chars. */ n = STRLEN(virp->vir_line); while (n > 0 && (virp->vir_line[n - 1] == NL --- 2589,2606 ---- ++p; len = getdigits(&p); buf = alloc((int)(len + 1)); + if (buf == NULL) + return count; p = buf; for (todo = len; todo > 0; todo -= n) { if (viminfo_readline(virp) || virp->vir_line[0] != '|' || virp->vir_line[1] != '<') + { /* file was truncated or garbled */ ! vim_free(buf); ! return count; ! } /* Get length of text, excluding |< and NL chars. */ n = STRLEN(virp->vir_line); while (n > 0 && (virp->vir_line[n - 1] == NL *************** *** 2623,2629 **** if (viminfo_readline(virp) || virp->vir_line[0] != '|' || virp->vir_line[1] != '<') /* file was truncated or garbled */ ! return 0; p = virp->vir_line + 2; } } --- 2628,2634 ---- if (viminfo_readline(virp) || virp->vir_line[0] != '|' || virp->vir_line[1] != '<') /* file was truncated or garbled */ ! return count; p = virp->vir_line + 2; } } *** ../vim-7.4.1917/src/ex_getln.c 2016-06-09 20:24:24.308049004 +0200 --- src/ex_getln.c 2016-06-11 15:16:47.093626924 +0200 *************** *** 6471,6476 **** --- 6471,6477 ---- vim_free(history[type][i].hisstr); vim_free(history[type]); history[type] = new_hist; + vim_free(tot_hist); } /* *** ../vim-7.4.1917/src/testdir/test_viminfo.vim 2016-06-11 14:47:34.488604982 +0200 --- src/testdir/test_viminfo.vim 2016-06-11 15:19:05.268105729 +0200 *************** *** 201,203 **** --- 201,222 ---- call delete('Xviminfo') endfunc + + func Test_viminfo_bad_syntax() + let lines = [] + call add(lines, '|<') " empty continuation line + call add(lines, '|234234234234234324,nothing') + call add(lines, '|1+"no comma"') + call add(lines, '|1,2,3,4,5,6,7') " too many items + call add(lines, '|1,"string version"') + call add(lines, '|1,>x') " bad continuation line + call add(lines, '|1,"x') " missing quote + call add(lines, '|1,"x\') " trailing backslash + call add(lines, '|1,,,,') "trailing comma + call add(lines, '|1,>234') " trailing continuation line + call writefile(lines, 'Xviminfo') + call assert_fails('rviminfo Xviminfo', 'E685:') + + call delete('Xviminfo') + endfunc + *** ../vim-7.4.1917/src/version.c 2016-06-11 14:47:34.492604940 +0200 --- src/version.c 2016-06-11 15:13:03.540091433 +0200 *************** *** 755,756 **** --- 755,758 ---- { /* Add new patch number below this line */ + /**/ + 1918, /**/ -- From "know your smileys": ~#:-( I just washed my hair, and I can't do nuthin' with it. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///