Skip to content
Snippets Groups Projects
Commit 5fe7a7fb authored by rswindell's avatar rswindell
Browse files

Added range checks when initializing textinfo.screenwidth and screeheight

(don't wrap around if value is > 255) - presumably these textinfo struct
members were left as unsigned chars (8-bits) to preserve compatiblity with
legacy conio apps, but I'm not sure. Perhaps we could increase these to
at least 16-bit integers or bigger in the future, in which case these range
checks would need to be removed or replaced.
parent 43c79170
Branches
Tags
No related merge requests found
......@@ -184,8 +184,17 @@ int bitmap_init_mode(int mode, int *width, int *height)
cio_textinfo.attribute=7;
cio_textinfo.normattr=7;
cio_textinfo.currmode=mode;
cio_textinfo.screenheight=vstat.rows;
cio_textinfo.screenwidth=vstat.cols;
if (vstat.rows > 0xff)
cio_textinfo.screenheight = 0xff;
else
cio_textinfo.screenheight = vstat.rows;
if (vstat.cols > 0xff)
cio_textinfo.screenwidth = 0xff;
else
cio_textinfo.screenwidth = vstat.cols;
cio_textinfo.curx=1;
cio_textinfo.cury=1;
cio_textinfo.winleft=1;
......
......@@ -548,8 +548,17 @@ int win32_initciolib(long inmode)
}
else {
/* Switch to closest mode to current screen size */
cio_textinfo.screenwidth=sbuff.srWindow.Right-sbuff.srWindow.Left+1;
cio_textinfo.screenheight=sbuff.srWindow.Bottom-sbuff.srWindow.Top+1;
unsigned screenwidth = sbuff.srWindow.Right - sbuff.srWindow.Left + 1;
unsigned screenheight = sbuff.srWindow.Bottom - sbuff.srWindow.Top + 1;
if (screenwidth > 0xff)
cio_textinfo.screenwidth = 0xff;
else
cio_textinfo.screenwidth = screenwidth;
if (screenheight > 0xff)
cio_textinfo.screenheight = 0xff;
else
cio_textinfo.screenheight = screenheight;
if(cio_textinfo.screenwidth>=132) {
if(cio_textinfo.screenheight<25)
win32_textmode(VESA_132X21);
......@@ -644,7 +653,7 @@ void win32_textmode(int mode)
if ((h=GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE)
return;
if (!SetConsoleScreenBufferSize(h,sz))
return;
return; // Note: This fails and returns here with large windows (e.g. width > 255)
if (!SetConsoleWindowInfo(h,TRUE,&rc))
return;
sz.X=vparams[modeidx].cols;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment