parsing fix, string safety

This commit is contained in:
dborth 2011-03-20 17:19:09 +00:00
parent 6ff121a1fd
commit 22d1cfea45
6 changed files with 33 additions and 34 deletions

View File

@ -290,7 +290,7 @@ bool MakeFilePath(char filepath[], int type, char * filename, int filenum)
sprintf (temppath, "%s%s/%s", pathPrefix[GCSettings.SaveMethod], folder, file);
}
CleanupPath(temppath); // cleanup path
strncpy(filepath, temppath, MAXPATHLEN);
snprintf(filepath, MAXPATHLEN, "%s", temppath);
return true;
}
@ -348,7 +348,7 @@ void StripExt(char* returnstring, char * inputstring)
{
char* loc_dot;
strncpy (returnstring, inputstring, MAXJOLIET);
snprintf(returnstring, MAXJOLIET, "%s", inputstring);
if(inputstring == NULL || strlen(inputstring) < 4)
return;
@ -516,8 +516,8 @@ int BrowserChangeFolder()
if(!UpdateDirName())
return -1;
CleanupPath(browser.dir);
HaltParseThread(); // halt parsing
CleanupPath(browser.dir);
ResetBrowser(); // reset browser
if(browser.dir[0] != 0)

View File

@ -23,7 +23,7 @@
typedef struct
{
char dir[MAXPATHLEN]; // directory path of browserList
char dir[MAXPATHLEN + 1]; // directory path of browserList
int numEntries; // # of entries in browserList
int selIndex; // currently selected index of browserList
int pageIndex; // starting index of browserList page display

View File

@ -453,8 +453,8 @@ void CreateAppPath(char * origpath)
path[2] = 'd';
}
if(ChangeInterface(&path[pos], SILENT))
strncpy(appPath, &path[pos], MAXPATHLEN);
appPath[MAXPATHLEN-1] = 0;
snprintf(appPath, MAXPATHLEN-1, "%s", &path[pos]);
free(path);
}
@ -481,12 +481,12 @@ bool ParseDirEntries()
char *ext;
char path[MAXPATHLEN+1];
struct dirent *entry;
struct dirent *entry = NULL;
struct stat filestat;
int i = 0;
while(i < 20)
while(i < 20 && !parseHalt)
{
entry = readdir(dir);
@ -530,7 +530,7 @@ bool ParseDirEntries()
break;
}
strncpy(browserList[browser.numEntries+i].filename, entry->d_name, MAXJOLIET);
snprintf(browserList[browser.numEntries+i].filename, MAXJOLIET, "%s", entry->d_name);
browserList[browser.numEntries+i].length = filestat.st_size;
browserList[browser.numEntries+i].mtime = filestat.st_mtime;
browserList[browser.numEntries+i].isdir = (filestat.st_mode & _IFDIR) == 0 ? 0 : 1; // flag this as a dir
@ -540,7 +540,7 @@ bool ParseDirEntries()
if(strcmp(entry->d_name, "..") == 0)
sprintf(browserList[browser.numEntries+i].displayname, "Up One Level");
else
strncpy(browserList[browser.numEntries+i].displayname, browserList[browser.numEntries+i].filename, MAXJOLIET);
snprintf(browserList[browser.numEntries+i].displayname, MAXJOLIET, "%s", browserList[browser.numEntries+i].filename);
browserList[browser.numEntries+i].icon = ICON_FOLDER;
}
else
@ -550,11 +550,14 @@ bool ParseDirEntries()
i++;
}
if(!parseHalt)
{
// Sort the file list
if(i >= 0)
qsort(browserList, browser.numEntries+i, sizeof(BROWSERENTRY), FileSortCallback);
browser.numEntries += i;
}
if(entry == NULL || parseHalt)
{
@ -562,7 +565,7 @@ bool ParseDirEntries()
dir = NULL;
// try to find and select the last loaded file
if(selectLoadedFile == 1 && parseHalt == 0 && loadedFile[0] != 0 && browser.dir[0] != 0)
if(selectLoadedFile == 1 && !parseHalt && loadedFile[0] != 0 && browser.dir[0] != 0)
{
int indexFound = -1;
@ -594,7 +597,6 @@ bool ParseDirEntries()
}
selectLoadedFile = 2; // selecting done
}
return false; // no more entries
}
return true; // more entries

View File

@ -455,7 +455,7 @@ int SzParse(char * filepath)
}
// parse information about this file to the file list structure
strncpy(browserList[SzJ].filename, SzF->Name, MAXJOLIET);
snprintf(browserList[SzJ].filename, MAXJOLIET, "%s", SzF->Name);
StripExt(browserList[SzJ].displayname, browserList[SzJ].filename);
browserList[SzJ].length = SzF->Size; // filesize
browserList[SzJ].isdir = 0; // only files will be displayed (-> no flags)

View File

@ -22,8 +22,7 @@ static char * GetDisplayText(char * t)
if(len < MAX_KEYBOARD_DISPLAY)
return t;
strncpy(tmptxt, &t[len-MAX_KEYBOARD_DISPLAY], MAX_KEYBOARD_DISPLAY);
tmptxt[MAX_KEYBOARD_DISPLAY-1] = 0;
snprintf(tmptxt, MAX_KEYBOARD_DISPLAY, "%s", &t[len-MAX_KEYBOARD_DISPLAY]);
return &tmptxt[0];
}
@ -41,8 +40,7 @@ GuiKeyboard::GuiKeyboard(char * t, u32 max)
focus = 0; // allow focus
alignmentHor = ALIGN_CENTRE;
alignmentVert = ALIGN_MIDDLE;
strncpy(kbtextstr, t, max);
kbtextstr[max] = 0;
snprintf(kbtextstr, 255, "%s", t);
kbtextmaxlen = max;
Key thekeys[4][11] = {

View File

@ -67,8 +67,8 @@ static lwp_t updatethread = LWP_THREAD_NULL;
static bool guiHalt = true;
static int showProgress = 0;
static char progressTitle[100];
static char progressMsg[200];
static char progressTitle[101];
static char progressMsg[201];
static int progressDone = 0;
static int progressTotal = 0;
@ -499,7 +499,7 @@ ShowProgress (const char *msg, int done, int total)
if(showProgress != 1)
CancelAction(); // wait for previous progress window to finish
strncpy(progressMsg, msg, 200);
snprintf(progressMsg, 200, "%s", msg);
sprintf(progressTitle, "Please Wait");
showProgress = 1;
progressTotal = total;
@ -522,7 +522,7 @@ ShowAction (const char *msg)
if(showProgress != 0)
CancelAction(); // wait for previous progress window to finish
strncpy(progressMsg, msg, 200);
snprintf(progressMsg, 200, "%s", msg);
sprintf(progressTitle, "Please Wait");
showProgress = 2;
progressDone = 0;
@ -1496,7 +1496,7 @@ static int MenuGameSaves(int action)
char filepath[1024];
char scrfile[1024];
char tmp[MAXJOLIET];
char tmp[MAXJOLIET+1];
int method = GCSettings.SaveMethod;
@ -1588,7 +1588,7 @@ static int MenuGameSaves(int action)
else
continue;
strncpy(tmp, browserList[i].filename, MAXJOLIET);
strcpy(tmp, browserList[i].filename);
tmp[len2-4] = 0;
n = FindGameSaveNum(tmp, method);
@ -1596,7 +1596,7 @@ static int MenuGameSaves(int action)
{
saves.type[j] = type;
saves.files[saves.type[j]][n] = 1;
strncpy(saves.filename[j], browserList[i].filename, MAXJOLIET);
strcpy(saves.filename[j], browserList[i].filename);
if(saves.type[j] == FILE_SNAPSHOT)
{
@ -3486,11 +3486,10 @@ static int MenuSettingsNetwork()
if(ret >= 0 || firstRun)
{
firstRun = false;
strncpy (options.value[0], GCSettings.smbip, 25);
options.value[0][25] = 0;
strncpy (options.value[1], GCSettings.smbshare, 19);
strncpy (options.value[2], GCSettings.smbuser, 19);
strncpy (options.value[3], GCSettings.smbpwd, 19);
snprintf (options.value[0], 25, "%s", GCSettings.smbip);
snprintf (options.value[1], 19, "%s", GCSettings.smbshare);
snprintf (options.value[2], 19, "%s", GCSettings.smbuser);
snprintf (options.value[3], 19, "%s", GCSettings.smbpwd);
optionBrowser.TriggerUpdate();
}