Fix buffer overfow with zeroing stack
This commit is contained in:
parent
a698156d4d
commit
ce9dabb83f
@ -38,13 +38,14 @@ extern GPickArealist* PickArealist;
|
|||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
|
||||||
void update_statuslines() {
|
void update_statuslines() {
|
||||||
|
# define BUFSIZE 200
|
||||||
char buf[200]; /* FIXME: it is need to use dynamic arrays in this fuction to prevent buffer overflow or screen garbage */
|
# define BUFLEN 199
|
||||||
char * const buf_end = buf+199;
|
char buf[BUFSIZE]=""; /* FIXME: it is need to use dynamic arrays in this fuction to prevent buffer overflow or screen garbage */
|
||||||
static char old_status_line[200] = "";
|
char * const buf_end = buf+BUFLEN;
|
||||||
char * const old_status_line_end = old_status_line+199;
|
static char old_status_line[BUFSIZE] = "";
|
||||||
|
char * const old_status_line_end = old_status_line+BUFLEN;
|
||||||
static int called = NO;
|
static int called = NO;
|
||||||
const int WIDE= sizeof(buf)>MAXCOL? MAXCOL : sizeof(buf)-1;
|
const int WIDE= BUFLEN>MAXCOL? MAXCOL : BUFLEN;
|
||||||
|
|
||||||
HandleGEvent(EVTT_REMOVEVOCBUF);
|
HandleGEvent(EVTT_REMOVEVOCBUF);
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ void update_statuslines() {
|
|||||||
called = YES;
|
called = YES;
|
||||||
|
|
||||||
vchar sep = _box_table(W_BSTAT, 3);
|
vchar sep = _box_table(W_BSTAT, 3);
|
||||||
char help[200], clkinfo[200];
|
char help[BUFSIZE], clkinfo[BUFSIZE];
|
||||||
*clkinfo = NUL;
|
*clkinfo = NUL;
|
||||||
*help = NUL;
|
*help = NUL;
|
||||||
|
|
||||||
@ -86,15 +87,12 @@ void update_statuslines() {
|
|||||||
int help_len = strlen(help);
|
int help_len = strlen(help);
|
||||||
int clk_len = strlen(clkinfo);
|
int clk_len = strlen(clkinfo);
|
||||||
int len = WIDE-help_len-clk_len-2;
|
int len = WIDE-help_len-clk_len-2;
|
||||||
// LOG.printf("! --- %i bytes help=\"%s\"", help_len, help?help:"NULL");
|
|
||||||
// LOG.printf("! --- %i bytes information=\"%s\"", len, information?information:"NULL");
|
|
||||||
// LOG.printf("! --- %i bytes clkinfo=\"%s\"", clk_len, clkinfo?clkinfo:"NULL");
|
|
||||||
gsprintf(PRINTF_DECLARE_BUFFER(buf), "%c%s%-*.*s%s ", goldmark, help, len, len, information, clkinfo);
|
gsprintf(PRINTF_DECLARE_BUFFER(buf), "%c%s%-*.*s%s ", goldmark, help, len, len, information, clkinfo);
|
||||||
|
|
||||||
char *begin = buf;
|
char *begin = buf;
|
||||||
char *obegin = old_status_line;
|
char *obegin = old_status_line;
|
||||||
char *end = buf + WIDE;
|
char *end = buf + WIDE-1; // last position before final '\0'
|
||||||
char *oend = old_status_line + WIDE;
|
char *oend = old_status_line + WIDE-1; // last position before final '\0'
|
||||||
while((*begin != NUL) and (*begin == *obegin) and (begin<buf_end) and (obegin<old_status_line_end)) {
|
while((*begin != NUL) and (*begin == *obegin) and (begin<buf_end) and (obegin<old_status_line_end)) {
|
||||||
++begin;
|
++begin;
|
||||||
++obegin;
|
++obegin;
|
||||||
@ -130,6 +128,8 @@ void update_statuslines() {
|
|||||||
gmou.ShowCursor();
|
gmou.ShowCursor();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
# undef BUFSIZE
|
||||||
|
# undef BUFLEN
|
||||||
} /* update_statuslines() */
|
} /* update_statuslines() */
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user