1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-18 15:26:23 -05:00

CID 39934: Fix potential buffer overflow.

This commit is contained in:
Renaud 2015-04-13 18:26:06 +08:00
parent e3b6d1e076
commit 4ac1913cd1

View File

@ -243,6 +243,17 @@ static void vtputc(int c)
++vtcol; ++vtcol;
} }
static int vtputs( const char *s) {
int n = 0 ;
while( *s) {
vtputc( *s++) ;
n += 1 ;
}
return n ;
}
/* /*
* Erase from the end of the software cursor to the end of the line on which * Erase from the end of the software cursor to the end of the line on which
* the software cursor is located. * the software cursor is located.
@ -1108,14 +1119,11 @@ static int updateline(int row, struct video *vp1, struct video *vp2)
*/ */
static void modeline(struct window *wp) static void modeline(struct window *wp)
{ {
char *cp;
int c;
int n; /* cursor position count */ int n; /* cursor position count */
struct buffer *bp; struct buffer *bp;
int i; /* loop index */ int i; /* loop index */
int lchar; /* character to draw line in buffer with */ int lchar; /* character to draw line in buffer with */
int firstm; /* is this the first mode? */ int firstm; /* is this the first mode? */
char tline[NLINE]; /* buffer for part of mode line */
n = wp->w_toprow + wp->w_ntrows; /* Location. */ n = wp->w_toprow + wp->w_ntrows; /* Location. */
vscreen[n]->v_flag |= VFCHG | VFREQ | VFCOL; /* Redraw next time. */ vscreen[n]->v_flag |= VFCHG | VFREQ | VFCOL; /* Redraw next time. */
@ -1154,64 +1162,37 @@ static void modeline(struct window *wp)
vtputc( ' ') ; vtputc( ' ') ;
n = 3 ; n = 3 ;
cp = PROGRAM_NAME_LONG " " VERSION ": " ; n += vtputs( PROGRAM_NAME_LONG " " VERSION ": ") ;
while ((c = *cp++) != 0) { n += vtputs( bp->b_bname) ;
vtputc(c); n += vtputs( " (") ;
++n;
}
cp = &bp->b_bname[0];
while ((c = *cp++) != 0) {
vtputc(c);
++n;
}
strcpy(tline, " (");
/* display the modes */ /* display the modes */
firstm = TRUE;
if ((bp->b_flag & BFTRUNC) != 0) { if ((bp->b_flag & BFTRUNC) != 0) {
firstm = FALSE; firstm = FALSE;
strcat(tline, "Truncated"); n += vtputs( "Truncated") ;
} } else
firstm = TRUE ;
for (i = 0; i < NUMMODES; i++) /* add in the mode flags */ for (i = 0; i < NUMMODES; i++) /* add in the mode flags */
if (wp->w_bufp->b_mode & (1 << i)) { if (wp->w_bufp->b_mode & (1 << i)) {
if (firstm != TRUE) if (firstm != TRUE)
strcat(tline, " "); n += vtputs( " ") ;
firstm = FALSE; else
strcat( tline, modename[ i]) ; firstm = FALSE ;
}
strcat(tline, ") ");
cp = &tline[0]; n += vtputs( modename[ i]) ;
while ((c = *cp++) != 0) {
vtputc(c);
++n;
} }
n += vtputs( ") ") ;
#if PKCODE #if PKCODE
if (bp->b_fname[0] != 0 && strcmp(bp->b_bname, bp->b_fname) != 0) if (bp->b_fname[0] != 0 && strcmp(bp->b_bname, bp->b_fname) != 0) {
#else #else
if (bp->b_fname[0] != 0) /* File name. */ if (bp->b_fname[0] != 0) { /* File name. */
n += vtputs( "File: ") ;
#endif #endif
{ n += vtputs( bp->b_fname) ;
#if PKCODE == 0
cp = "File: ";
while ((c = *cp++) != 0) {
vtputc(c);
++n;
}
#endif
cp = &bp->b_fname[0];
while ((c = *cp++) != 0) {
vtputc(c);
++n;
}
vtputc(' '); vtputc(' ');
++n; ++n;
} }
@ -1225,6 +1206,7 @@ static void modeline(struct window *wp)
struct line *lp = wp->w_linep; struct line *lp = wp->w_linep;
int rows = wp->w_ntrows; int rows = wp->w_ntrows;
char *msg = NULL; char *msg = NULL;
char tline[ 6] ; /* buffer for part of mode line */
vtcol = n - 7; /* strlen(" top ") plus a couple */ vtcol = n - 7; /* strlen(" top ") plus a couple */
while (rows--) { while (rows--) {
@ -1282,11 +1264,7 @@ static void modeline(struct window *wp)
} }
} }
cp = msg; n += vtputs( msg) ;
while ((c = *cp++) != 0) {
vtputc(c);
++n;
}
} }
} }