parsing fix, string safety

This commit is contained in:
dborth 2011-03-20 17:16:07 +00:00
parent 053106052e
commit b2f27d982c
6 changed files with 35 additions and 38 deletions

View File

@ -295,7 +295,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;
}
@ -412,7 +412,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;
@ -541,8 +541,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

@ -455,8 +455,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);
}
@ -483,12 +483,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);
@ -515,7 +515,7 @@ bool ParseDirEntries()
{
if(ext == NULL)
continue;
if( stricmp(ext, "nes") != 0 && stricmp(ext, "fds") != 0 &&
stricmp(ext, "nsf") != 0 && stricmp(ext, "unf") != 0 &&
stricmp(ext, "nez") != 0 && stricmp(ext, "unif") != 0 &&
@ -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++;
}
// Sort the file list
if(i >= 0)
qsort(browserList, browser.numEntries+i, sizeof(BROWSERENTRY), FileSortCallback);
browser.numEntries += 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

@ -224,7 +224,7 @@ GetFirstZipFilename ()
ErrorPrompt("Error - Invalid ZIP file!");
return NULL;
}
firstFilename = &tempbuffer[30]; // first filename of a ZIP starts 31 bytes in
firstFilename[namelength] = 0; // truncate at filename length
return strdup(firstFilename);
@ -456,7 +456,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

@ -73,8 +73,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;
@ -515,7 +515,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;
@ -538,7 +538,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;
@ -1547,7 +1547,7 @@ static int MenuGameSaves(int action)
SaveList saves;
char filepath[1024];
char scrfile[1024];
char tmp[MAXJOLIET];
char tmp[MAXJOLIET+1];
struct stat filestat;
struct tm * timeinfo;
int method = GCSettings.SaveMethod;
@ -1640,7 +1640,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);
@ -1648,7 +1648,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_STATE)
{
@ -3763,13 +3763,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();
}