mirror of
https://github.com/dborth/fceugx.git
synced 2025-01-09 23:29:25 +01:00
parsing fix, string safety
This commit is contained in:
parent
053106052e
commit
b2f27d982c
@ -295,7 +295,7 @@ bool MakeFilePath(char filepath[], int type, char * filename, int filenum)
|
|||||||
sprintf (temppath, "%s%s/%s", pathPrefix[GCSettings.SaveMethod], folder, file);
|
sprintf (temppath, "%s%s/%s", pathPrefix[GCSettings.SaveMethod], folder, file);
|
||||||
}
|
}
|
||||||
CleanupPath(temppath); // cleanup path
|
CleanupPath(temppath); // cleanup path
|
||||||
strncpy(filepath, temppath, MAXPATHLEN);
|
snprintf(filepath, MAXPATHLEN, "%s", temppath);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -412,7 +412,7 @@ void StripExt(char* returnstring, char * inputstring)
|
|||||||
{
|
{
|
||||||
char* loc_dot;
|
char* loc_dot;
|
||||||
|
|
||||||
strncpy (returnstring, inputstring, MAXJOLIET);
|
snprintf(returnstring, MAXJOLIET, "%s", inputstring);
|
||||||
|
|
||||||
if(inputstring == NULL || strlen(inputstring) < 4)
|
if(inputstring == NULL || strlen(inputstring) < 4)
|
||||||
return;
|
return;
|
||||||
@ -541,8 +541,8 @@ int BrowserChangeFolder()
|
|||||||
if(!UpdateDirName())
|
if(!UpdateDirName())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
CleanupPath(browser.dir);
|
|
||||||
HaltParseThread(); // halt parsing
|
HaltParseThread(); // halt parsing
|
||||||
|
CleanupPath(browser.dir);
|
||||||
ResetBrowser(); // reset browser
|
ResetBrowser(); // reset browser
|
||||||
|
|
||||||
if(browser.dir[0] != 0)
|
if(browser.dir[0] != 0)
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char dir[MAXPATHLEN]; // directory path of browserList
|
char dir[MAXPATHLEN + 1]; // directory path of browserList
|
||||||
int numEntries; // # of entries in browserList
|
int numEntries; // # of entries in browserList
|
||||||
int selIndex; // currently selected index of browserList
|
int selIndex; // currently selected index of browserList
|
||||||
int pageIndex; // starting index of browserList page display
|
int pageIndex; // starting index of browserList page display
|
||||||
|
@ -455,8 +455,8 @@ void CreateAppPath(char * origpath)
|
|||||||
path[2] = 'd';
|
path[2] = 'd';
|
||||||
}
|
}
|
||||||
if(ChangeInterface(&path[pos], SILENT))
|
if(ChangeInterface(&path[pos], SILENT))
|
||||||
strncpy(appPath, &path[pos], MAXPATHLEN);
|
snprintf(appPath, MAXPATHLEN-1, "%s", &path[pos]);
|
||||||
appPath[MAXPATHLEN-1] = 0;
|
|
||||||
free(path);
|
free(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -483,12 +483,12 @@ bool ParseDirEntries()
|
|||||||
|
|
||||||
char *ext;
|
char *ext;
|
||||||
char path[MAXPATHLEN+1];
|
char path[MAXPATHLEN+1];
|
||||||
struct dirent *entry;
|
struct dirent *entry = NULL;
|
||||||
struct stat filestat;
|
struct stat filestat;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while(i < 20)
|
while(i < 20 && !parseHalt)
|
||||||
{
|
{
|
||||||
entry = readdir(dir);
|
entry = readdir(dir);
|
||||||
|
|
||||||
@ -515,7 +515,7 @@ bool ParseDirEntries()
|
|||||||
{
|
{
|
||||||
if(ext == NULL)
|
if(ext == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if( stricmp(ext, "nes") != 0 && stricmp(ext, "fds") != 0 &&
|
if( stricmp(ext, "nes") != 0 && stricmp(ext, "fds") != 0 &&
|
||||||
stricmp(ext, "nsf") != 0 && stricmp(ext, "unf") != 0 &&
|
stricmp(ext, "nsf") != 0 && stricmp(ext, "unf") != 0 &&
|
||||||
stricmp(ext, "nez") != 0 && stricmp(ext, "unif") != 0 &&
|
stricmp(ext, "nez") != 0 && stricmp(ext, "unif") != 0 &&
|
||||||
@ -530,7 +530,7 @@ bool ParseDirEntries()
|
|||||||
break;
|
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].length = filestat.st_size;
|
||||||
browserList[browser.numEntries+i].mtime = filestat.st_mtime;
|
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
|
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)
|
if(strcmp(entry->d_name, "..") == 0)
|
||||||
sprintf(browserList[browser.numEntries+i].displayname, "Up One Level");
|
sprintf(browserList[browser.numEntries+i].displayname, "Up One Level");
|
||||||
else
|
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;
|
browserList[browser.numEntries+i].icon = ICON_FOLDER;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -550,11 +550,14 @@ bool ParseDirEntries()
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort the file list
|
if(!parseHalt)
|
||||||
if(i >= 0)
|
{
|
||||||
qsort(browserList, browser.numEntries+i, sizeof(BROWSERENTRY), FileSortCallback);
|
// Sort the file list
|
||||||
|
if(i >= 0)
|
||||||
browser.numEntries += i;
|
qsort(browserList, browser.numEntries+i, sizeof(BROWSERENTRY), FileSortCallback);
|
||||||
|
|
||||||
|
browser.numEntries += i;
|
||||||
|
}
|
||||||
|
|
||||||
if(entry == NULL || parseHalt)
|
if(entry == NULL || parseHalt)
|
||||||
{
|
{
|
||||||
@ -562,7 +565,7 @@ bool ParseDirEntries()
|
|||||||
dir = NULL;
|
dir = NULL;
|
||||||
|
|
||||||
// try to find and select the last loaded file
|
// 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;
|
int indexFound = -1;
|
||||||
|
|
||||||
@ -594,7 +597,6 @@ bool ParseDirEntries()
|
|||||||
}
|
}
|
||||||
selectLoadedFile = 2; // selecting done
|
selectLoadedFile = 2; // selecting done
|
||||||
}
|
}
|
||||||
|
|
||||||
return false; // no more entries
|
return false; // no more entries
|
||||||
}
|
}
|
||||||
return true; // more entries
|
return true; // more entries
|
||||||
|
@ -224,7 +224,7 @@ GetFirstZipFilename ()
|
|||||||
ErrorPrompt("Error - Invalid ZIP file!");
|
ErrorPrompt("Error - Invalid ZIP file!");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
firstFilename = &tempbuffer[30]; // first filename of a ZIP starts 31 bytes in
|
firstFilename = &tempbuffer[30]; // first filename of a ZIP starts 31 bytes in
|
||||||
firstFilename[namelength] = 0; // truncate at filename length
|
firstFilename[namelength] = 0; // truncate at filename length
|
||||||
return strdup(firstFilename);
|
return strdup(firstFilename);
|
||||||
@ -456,7 +456,7 @@ int SzParse(char * filepath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parse information about this file to the file list structure
|
// 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);
|
StripExt(browserList[SzJ].displayname, browserList[SzJ].filename);
|
||||||
browserList[SzJ].length = SzF->Size; // filesize
|
browserList[SzJ].length = SzF->Size; // filesize
|
||||||
browserList[SzJ].isdir = 0; // only files will be displayed (-> no flags)
|
browserList[SzJ].isdir = 0; // only files will be displayed (-> no flags)
|
||||||
|
@ -22,8 +22,7 @@ static char * GetDisplayText(char * t)
|
|||||||
if(len < MAX_KEYBOARD_DISPLAY)
|
if(len < MAX_KEYBOARD_DISPLAY)
|
||||||
return t;
|
return t;
|
||||||
|
|
||||||
strncpy(tmptxt, &t[len-MAX_KEYBOARD_DISPLAY], MAX_KEYBOARD_DISPLAY);
|
snprintf(tmptxt, MAX_KEYBOARD_DISPLAY, "%s", &t[len-MAX_KEYBOARD_DISPLAY]);
|
||||||
tmptxt[MAX_KEYBOARD_DISPLAY-1] = 0;
|
|
||||||
return &tmptxt[0];
|
return &tmptxt[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,8 +40,7 @@ GuiKeyboard::GuiKeyboard(char * t, u32 max)
|
|||||||
focus = 0; // allow focus
|
focus = 0; // allow focus
|
||||||
alignmentHor = ALIGN_CENTRE;
|
alignmentHor = ALIGN_CENTRE;
|
||||||
alignmentVert = ALIGN_MIDDLE;
|
alignmentVert = ALIGN_MIDDLE;
|
||||||
strncpy(kbtextstr, t, max);
|
snprintf(kbtextstr, 255, "%s", t);
|
||||||
kbtextstr[max] = 0;
|
|
||||||
kbtextmaxlen = max;
|
kbtextmaxlen = max;
|
||||||
|
|
||||||
Key thekeys[4][11] = {
|
Key thekeys[4][11] = {
|
||||||
|
@ -73,8 +73,8 @@ static lwp_t updatethread = LWP_THREAD_NULL;
|
|||||||
static bool guiHalt = true;
|
static bool guiHalt = true;
|
||||||
static int showProgress = 0;
|
static int showProgress = 0;
|
||||||
|
|
||||||
static char progressTitle[100];
|
static char progressTitle[101];
|
||||||
static char progressMsg[200];
|
static char progressMsg[201];
|
||||||
static int progressDone = 0;
|
static int progressDone = 0;
|
||||||
static int progressTotal = 0;
|
static int progressTotal = 0;
|
||||||
|
|
||||||
@ -515,7 +515,7 @@ ShowProgress (const char *msg, int done, int total)
|
|||||||
if(showProgress != 1)
|
if(showProgress != 1)
|
||||||
CancelAction(); // wait for previous progress window to finish
|
CancelAction(); // wait for previous progress window to finish
|
||||||
|
|
||||||
strncpy(progressMsg, msg, 200);
|
snprintf(progressMsg, 200, "%s", msg);
|
||||||
sprintf(progressTitle, "Please Wait");
|
sprintf(progressTitle, "Please Wait");
|
||||||
showProgress = 1;
|
showProgress = 1;
|
||||||
progressTotal = total;
|
progressTotal = total;
|
||||||
@ -538,7 +538,7 @@ ShowAction (const char *msg)
|
|||||||
if(showProgress != 0)
|
if(showProgress != 0)
|
||||||
CancelAction(); // wait for previous progress window to finish
|
CancelAction(); // wait for previous progress window to finish
|
||||||
|
|
||||||
strncpy(progressMsg, msg, 200);
|
snprintf(progressMsg, 200, "%s", msg);
|
||||||
sprintf(progressTitle, "Please Wait");
|
sprintf(progressTitle, "Please Wait");
|
||||||
showProgress = 2;
|
showProgress = 2;
|
||||||
progressDone = 0;
|
progressDone = 0;
|
||||||
@ -1547,7 +1547,7 @@ static int MenuGameSaves(int action)
|
|||||||
SaveList saves;
|
SaveList saves;
|
||||||
char filepath[1024];
|
char filepath[1024];
|
||||||
char scrfile[1024];
|
char scrfile[1024];
|
||||||
char tmp[MAXJOLIET];
|
char tmp[MAXJOLIET+1];
|
||||||
struct stat filestat;
|
struct stat filestat;
|
||||||
struct tm * timeinfo;
|
struct tm * timeinfo;
|
||||||
int method = GCSettings.SaveMethod;
|
int method = GCSettings.SaveMethod;
|
||||||
@ -1640,7 +1640,7 @@ static int MenuGameSaves(int action)
|
|||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
strncpy(tmp, browserList[i].filename, MAXJOLIET);
|
strcpy(tmp, browserList[i].filename);
|
||||||
tmp[len2-4] = 0;
|
tmp[len2-4] = 0;
|
||||||
n = FindGameSaveNum(tmp, method);
|
n = FindGameSaveNum(tmp, method);
|
||||||
|
|
||||||
@ -1648,7 +1648,7 @@ static int MenuGameSaves(int action)
|
|||||||
{
|
{
|
||||||
saves.type[j] = type;
|
saves.type[j] = type;
|
||||||
saves.files[saves.type[j]][n] = 1;
|
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)
|
if(saves.type[j] == FILE_STATE)
|
||||||
{
|
{
|
||||||
@ -3763,13 +3763,10 @@ static int MenuSettingsNetwork()
|
|||||||
if(ret >= 0 || firstRun)
|
if(ret >= 0 || firstRun)
|
||||||
{
|
{
|
||||||
firstRun = false;
|
firstRun = false;
|
||||||
|
snprintf (options.value[0], 25, "%s", GCSettings.smbip);
|
||||||
strncpy (options.value[0], GCSettings.smbip, 25);
|
snprintf (options.value[1], 19, "%s", GCSettings.smbshare);
|
||||||
options.value[0][25] = 0;
|
snprintf (options.value[2], 19, "%s", GCSettings.smbuser);
|
||||||
strncpy (options.value[1], GCSettings.smbshare, 19);
|
snprintf (options.value[3], 19, "%s", GCSettings.smbpwd);
|
||||||
strncpy (options.value[2], GCSettings.smbuser, 19);
|
|
||||||
strncpy (options.value[3], GCSettings.smbpwd, 19);
|
|
||||||
|
|
||||||
optionBrowser.TriggerUpdate();
|
optionBrowser.TriggerUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user