Fixed potential buffer overflow situations in gui Panels

This commit is contained in:
Dimitris Panokostas 2019-02-08 20:46:43 +01:00
parent 05dbf48da3
commit 7d06843ea7
8 changed files with 16 additions and 17 deletions

View file

@ -95,7 +95,7 @@ public:
if (strlen(i->Description) > 0)
{
strncat(tmp, " (", MAX_DPATH - 1);
strncat(tmp, i->Description, MAX_DPATH - 1);
strncat(tmp, i->Description, MAX_DPATH - 3);
strncat(tmp, ")", MAX_DPATH - 1);
}
configs.emplace_back(tmp);
@ -142,7 +142,7 @@ public:
{
fetch_configurationpath(filename, MAX_DPATH);
strncat(filename, txtName->getText().c_str(), MAX_DPATH - 1);
strncat(filename, ".uae", MAX_DPATH);
strncat(filename, ".uae", MAX_DPATH - 1);
strncpy(changed_prefs.description, txtDesc->getText().c_str(), 256);
if (cfgfile_save(&changed_prefs, filename, 0))
RefreshPanelConfig();

View file

@ -466,12 +466,11 @@ void InitPanelCustom(const struct _ConfigCategory& category)
auto posY = 144 + 40;
for (i = 0; i < 7; ++i)
{
category.panel->add(lblCustomAction[i], DISTANCE_BORDER/2, posY);
category.panel->add(cboCustomAction[i], DISTANCE_BORDER/2 + lblCustomAction[i]->getWidth() + 4, posY);
category.panel->add(lblCustomAction[i], DISTANCE_BORDER / 2, posY);
category.panel->add(cboCustomAction[i], DISTANCE_BORDER / 2 + lblCustomAction[i]->getWidth() + 4, posY);
posY = posY + DROPDOWN_HEIGHT + 6;
}
posY = 144 + 40;
for (i = 7; i < 14; ++i)
{
@ -479,8 +478,8 @@ void InitPanelCustom(const struct _ConfigCategory& category)
category.panel->add(cboCustomAction[i], DISTANCE_BORDER + lblCustomAction[i]->getWidth() + 290 + 4, posY);
posY = posY + DROPDOWN_HEIGHT + 6;
}
category.panel->add(chkAnalogRemap, DISTANCE_BORDER + lblCustomAction[0]->getWidth(), posY);
category.panel->add(chkAnalogRemap, DISTANCE_BORDER + lblCustomAction[0]->getWidth(), posY);
posY += chkAnalogRemap->getHeight() + DISTANCE_NEXT_Y;
category.panel->add(lblPortInput, DISTANCE_BORDER, 144);

View file

@ -258,7 +258,7 @@ void InitPanelDisplay(const struct _ConfigCategory& category)
grpLineMode = new gcn::Window("Line mode");
#ifdef USE_SDL2
grpLineMode->setPosition(
grpScalingMethod->getWidth() + DISTANCE_BORDER + DISTANCE_NEXT_X,
grpScalingMethod->getWidth() + DISTANCE_BORDER + DISTANCE_NEXT_X,
posY - DISTANCE_BORDER - grpScalingMethod->getHeight() - DISTANCE_NEXT_Y);
#else
grpLineMode->setPosition(DISTANCE_BORDER, posY);

View file

@ -206,7 +206,7 @@ static void SetControlState(const int model)
static void AdjustPrefs(void)
{
const auto old_cs = changed_prefs.cs_compatible;
//const auto old_cs = changed_prefs.cs_compatible;
built_in_prefs(&changed_prefs, quickstart_model, quickstart_conf, 0, 0);
switch (quickstart_model)

View file

@ -109,7 +109,7 @@ public:
return;
strncpy(tmp, workingDir, MAX_DPATH - 1);
strncat(tmp, "/", MAX_DPATH - 1);
strncat(tmp, txtFilename->getText().c_str(), MAX_DPATH - 1);
strncat(tmp, txtFilename->getText().c_str(), MAX_DPATH - 2);
if (strstr(tmp, filefilter[0]) == nullptr)
strncat(tmp, filefilter[0], MAX_DPATH - 1);
if (my_existsfile(tmp) == 1)
@ -122,7 +122,7 @@ public:
if (fileList->isDir(selected_item))
return; // Directory selected -> Ok not possible
strncat(workingDir, "/", MAX_DPATH - 1);
strncat(workingDir, fileList->getElementAt(selected_item).c_str(), MAX_DPATH - 1);
strncat(workingDir, fileList->getElementAt(selected_item).c_str(), MAX_DPATH - 2);
dialogResult = true;
}
}
@ -176,7 +176,7 @@ public:
const auto selected_item = lstFiles->getSelected();
strncpy(foldername, workingDir, MAX_DPATH);
strncat(foldername, "/", MAX_DPATH - 1);
strncat(foldername, fileList->getElementAt(selected_item).c_str(), MAX_DPATH - 1);
strncat(foldername, fileList->getElementAt(selected_item).c_str(), MAX_DPATH - 2);
if (fileList->isDir(selected_item))
checkfoldername(foldername);
else if (!createNew)

View file

@ -125,7 +125,7 @@ public:
const auto selected_item = lstFolders->getSelected();
strncpy(foldername, workingDir, MAX_DPATH - 1);
strncat(foldername, "/", MAX_DPATH - 1);
strncat(foldername, dirList.getElementAt(selected_item).c_str(), MAX_DPATH - 1);
strncat(foldername, dirList.getElementAt(selected_item).c_str(), MAX_DPATH - 2);
volName = dirList.getElementAt(selected_item);
checkfoldername(foldername);
}
@ -369,7 +369,7 @@ bool SelectFolder(const char* title, char* value)
{
strncpy(value, workingDir, MAX_DPATH);
if (value[strlen(value) - 1] != '/')
strncat(value, "/", MAX_DPATH);
strncat(value, "/", MAX_DPATH - 1);
}
return dialogResult;
}

View file

@ -27,7 +27,7 @@ namespace gcn
label = new Label(caption);
label->setHeight(16);
Image* img = Image::load(imagepath);
auto img = Image::load(imagepath);
icon = new Icon(img);
icon->setSize(16, 16);

View file

@ -791,8 +791,8 @@ namespace widgets
strncat(tmp, last_loaded_config, MAX_DPATH - 1);
else
{
strncat(tmp, OPTIONSFILENAME, MAX_DPATH);
strncat(tmp, ".uae", MAX_DPATH);
strncat(tmp, OPTIONSFILENAME, MAX_DPATH - 1);
strncat(tmp, ".uae", MAX_DPATH - 10);
}
uae_restart(-1, tmp);
gui_running = false;