diff --git a/src/ChangeLog b/src/ChangeLog index 83174f010..7d9b50912 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2004-08-19 Pavel Shirshov + + * screen.c (paint_frame): Fix possible buffer overflow. + 2004-08-18 Pavel Shirshov * background.c (do_background): Use O_RDWR when opening diff --git a/src/screen.c b/src/screen.c index 8eb53c45d..2b5bd5e5e 100644 --- a/src/screen.c +++ b/src/screen.c @@ -1060,7 +1060,7 @@ paint_frame (WPanel *panel) int spaces, extra; int side, width; - char *txt, buffer[30]; /*Hope that this is enough ;-) */ + char *txt; if (!panel->split) adjust_top_file (panel); @@ -1086,18 +1086,14 @@ paint_frame (WPanel *panel) txt = format->title; header_len = strlen (txt); - if (header_len > format->field_len){ - strcpy (buffer, txt); - txt = buffer; - txt [format->field_len] = 0; - header_len = strlen (txt); - } + if (header_len > format->field_len) + header_len = format->field_len; attrset (MARKED_COLOR); spaces = (format->field_len - header_len) / 2; extra = (format->field_len - header_len) % 2; - printw ("%*s%-s%*s", spaces, "", - txt, spaces+extra, ""); + printw ("%*s%.*s%*s", spaces, "", + header_len, txt, spaces+extra, ""); width -= 2 * spaces + extra + header_len; } else { attrset (NORMAL_COLOR);