To: vim-dev@vim.org Subject: patch 5.5.033 Fcc: outbox From: Bram Moolenaar ------------ Patch 5.5.033 Problem: When reading from stdin, a long line in viminfo would mess up the file message. readfile() uses IObuff for keep_msg, which could be overwritten by anyone. Solution: Copy the message from IObuff to msg_buf and set keep_msg to that. Also change vim_fgets() to not use IObuff any longer. Files: src/fileio.c *** ../vim-5.5.32/src/fileio.c Wed Sep 22 10:06:22 1999 --- src/fileio.c Sun Oct 24 20:18:27 1999 *************** *** 936,946 **** if (msg_add_fileformat(fileformat)) c = TRUE; msg_add_lines(c, (long)linecnt, filesize); ! /* When reading from stdin, the screen will be cleared next; keep ! * the message to repeat it later. */ keep_msg = msg_trunc_attr(IObuff, FALSE, 0); keep_msg_attr = 0; ! if (!read_stdin) keep_msg = NULL; } --- 936,955 ---- if (msg_add_fileformat(fileformat)) c = TRUE; msg_add_lines(c, (long)linecnt, filesize); ! keep_msg = msg_trunc_attr(IObuff, FALSE, 0); keep_msg_attr = 0; ! if (read_stdin) ! { ! /* When reading from stdin, the screen will be cleared next; ! * keep the message to repeat it later. ! * Copy the message (truncated) to msg_buf, because IObuff ! * could be overwritten any time. */ ! STRNCPY(msg_buf, keep_msg, MSG_BUF_LEN); ! msg_buf[MSG_BUF_LEN - 1] = NUL; ! keep_msg = msg_buf; ! } ! else keep_msg = NULL; } *************** *** 2676,2683 **** * * Like fgets(), but if the file line is too long, it is truncated and the * rest of the line is thrown away. Returns TRUE for end-of-file. - * Note: do not pass IObuff as the buffer since this is used to read and - * discard the extra part of any long lines. */ int vim_fgets(buf, size, fp) --- 2685,2690 ---- *************** *** 2685,2691 **** int size; FILE *fp; { ! char *eof; buf[size - 2] = NUL; eof = fgets((char *)buf, size, fp); --- 2692,2700 ---- int size; FILE *fp; { ! char *eof; ! #define FGETS_SIZE 200 ! char tbuf[FGETS_SIZE]; buf[size - 2] = NUL; eof = fgets((char *)buf, size, fp); *************** *** 2696,2704 **** /* Now throw away the rest of the line: */ do { ! IObuff[IOSIZE - 2] = NUL; ! fgets((char *)IObuff, IOSIZE, fp); ! } while (IObuff[IOSIZE - 2] != NUL && IObuff[IOSIZE - 2] != '\n'); } return (eof == NULL); } --- 2705,2713 ---- /* Now throw away the rest of the line: */ do { ! tbuf[FGETS_SIZE - 2] = NUL; ! fgets((char *)tbuf, FGETS_SIZE, fp); ! } while (tbuf[FGETS_SIZE - 2] != NUL && tbuf[FGETS_SIZE - 2] != '\n'); } return (eof == NULL); } *** ../vim-5.5.32/src/version.c Sun Oct 24 20:24:39 1999 --- src/version.c Sun Oct 24 20:24:16 1999 *************** *** 420,420 **** --- 420,421 ---- { /* Add new patch number below this line */ + 33, -- ARTHUR: ... and I am your king .... OLD WOMAN: Ooooh! I didn't know we had a king. I thought we were an autonomous collective ... "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD --/-/---- Bram Moolenaar ---- Bram@moolenaar.net ---- Bram@vim.org ---\-\-- \ \ www.vim.org/iccf www.moolenaar.net www.vim.org / /