1
0
Fork 0

Add patch 1239754 from Moe. This patches fixes a few crashes by checking the SDL_SetMode return value and it changes strncopy to a safe_strncopy which adds a 0 to each string copied

Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2240
This commit is contained in:
Peter Veenstra 2005-07-19 19:45:33 +00:00
parent 3429a18dc4
commit c7c2ee5d5a
14 changed files with 56 additions and 41 deletions

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: cdrom_aspi_win32.cpp,v 1.13 2005-02-10 10:20:50 qbix79 Exp $ */
/* $Id: cdrom_aspi_win32.cpp,v 1.14 2005-07-19 19:45:16 qbix79 Exp $ */
#if defined (WIN32)
@ -219,8 +219,7 @@ bool CDROM_Interface_Aspi::GetVendor(BYTE HA_num, BYTE SCSI_Id, BYTE SCSI_Lun, c
strcpy (szBuffer, "error" );
return false;
} else {
strncpy(szBuffer,szBuffer+8,25);
szBuffer[25] = 0;
safe_strncpy(szBuffer,szBuffer+8,26);
int len = strlen(szBuffer);
for (int i=0; i<len; i++) if (szBuffer[i]<=32) szBuffer[i]='_';
};

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: cdrom_image.cpp,v 1.8 2005-06-23 18:34:29 qbix79 Exp $ */
/* $Id: cdrom_image.cpp,v 1.9 2005-07-19 19:45:16 qbix79 Exp $ */
#include <cctype>
#include <cmath>
@ -29,6 +29,7 @@
#include <sys/stat.h>
#include "cdrom.h"
#include "drives.h"
#include "support.h"
#if !defined(WIN32)
#include <libgen.h>
@ -399,8 +400,7 @@ static string dirname(const char * file) {
else {
int len = (int)(sep - file);
char tmp[MAX_FILENAME_LENGTH];
strncpy(tmp, file, len);
tmp[len] = '\0';
safe_strncpy(tmp, file, len+1);
return tmp;
}
}
@ -417,7 +417,7 @@ bool CDROM_Interface_Image::LoadCueSheet(char *cuefile)
bool success;
bool canAddTrack = false;
char tmp[MAX_FILENAME_LENGTH]; // dirname can change its argument
strncpy(tmp, cuefile, MAX_FILENAME_LENGTH);
safe_strncpy(tmp, cuefile, MAX_FILENAME_LENGTH);
string pathname(dirname(tmp));
ifstream in;
in.open(cuefile, ios::in);
@ -595,7 +595,7 @@ bool CDROM_Interface_Image::GetRealFileName(string &filename, string &pathname)
// finally check if file is in a dosbox local drive
char fullname[CROSS_LEN];
char tmp[CROSS_LEN];
strncpy(tmp, filename.c_str(), CROSS_LEN);
safe_strncpy(tmp, filename.c_str(), CROSS_LEN);
Bit8u drive;
if (!DOS_MakeName(tmp, fullname, &drive)) return false;

View file

@ -19,6 +19,7 @@
#include <string.h>
#include "cdrom.h"
#include "support.h"
#if defined (LINUX)
#include <fcntl.h>
@ -45,7 +46,7 @@ bool CDROM_Interface_Ioctl::GetUPC(unsigned char& attr, char* upc)
if (ret > 0) {
attr = 0;
strncpy(upc, (char*)cdrom_mcn.medium_catalog_number, 14);
safe_strncpy(upc, (char*)cdrom_mcn.medium_catalog_number, 14);
}
return (ret > 0);
@ -86,7 +87,7 @@ bool CDROM_Interface_Ioctl::SetDevice(char* path, int forceCD)
if (success) {
const char* tmp = SDL_CDName(forceCD);
if (tmp) strncpy(device_name, tmp, 512);
if (tmp) safe_strncpy(device_name, tmp, 512);
else success = false;
}

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: dos_programs.cpp,v 1.36 2005-04-06 20:48:14 qbix79 Exp $ */
/* $Id: dos_programs.cpp,v 1.37 2005-07-19 19:45:16 qbix79 Exp $ */
#include <stdlib.h>
#include <string.h>
@ -422,7 +422,7 @@ void LOADFIX::Run(void)
if (cmd->FindCommand(commandNr++,temp_line)) {
// get Filename
char filename[128];
strncpy(filename,temp_line.c_str(),128);
safe_strncpy(filename,temp_line.c_str(),128);
// Setup commandline
bool ok;
char args[256];
@ -570,10 +570,10 @@ public:
// convert dosbox filename to system filename
char fullname[CROSS_LEN];
char tmp[CROSS_LEN];
strncpy(tmp, temp_line.c_str(), CROSS_LEN);
safe_strncpy(tmp, temp_line.c_str(), CROSS_LEN);
Bit8u drive;
if (!DOS_MakeName(tmp, fullname, &drive)) {
if (!DOS_MakeName(tmp, fullname, &drive) || strncmp(Drives[drive]->GetInfo(),"local directory",15)) {
WriteOut(MSG_Get("PROGRAM_IMGMOUNG_FILE_NOT_FOUND"));
return;
}

View file

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: drive_cache.cpp,v 1.43 2005-04-21 18:43:28 qbix79 Exp $ */
/* $Id: drive_cache.cpp,v 1.44 2005-07-19 19:45:31 qbix79 Exp $ */
#include "drives.h"
#include "dos_inc.h"
@ -262,8 +262,7 @@ void DOS_Drive_Cache::CacheOut(const char* path, bool ignoreLastDir)
char tmp[CROSS_LEN] = { 0 };
Bit32s len = strrchr(path,CROSS_FILESPLIT) - path;
if (len>0) {
strncpy(tmp,path,len);
tmp[len] = 0;
safe_strncpy(tmp,path,len+1);
} else {
strcpy(tmp,path);
}
@ -463,11 +462,10 @@ void DOS_Drive_Cache::CreateShortName(CFileInfo* curDir, CFileInfo* info)
info->shortNr = CreateShortNameID(curDir,tmpName);
sprintf(buffer,"%d",info->shortNr);
// Copy first letters
Bit16u tocopy;
Bit16u tocopy = 0;
if (len+strlen(buffer)+1>8) tocopy = 8 - strlen(buffer) - 1;
else tocopy = len;
strncpy(info->shortname,tmpName,tocopy);
info->shortname[tocopy] = 0;
safe_strncpy(info->shortname,tmpName,tocopy+1);
// Copy number
strcat(info->shortname,"~");
strcat(info->shortname,buffer);
@ -527,7 +525,7 @@ DOS_Drive_Cache::CFileInfo* DOS_Drive_Cache::FindDirInfo(const char* path, char*
do {
// bool errorcheck = false;
pos = strchr(start,CROSS_FILESPLIT);
if (pos) { strncpy(dir,start,pos-start); dir[pos-start] = 0; /*errorcheck = true;*/ }
if (pos) { safe_strncpy(dir,start,pos-start+1); /*errorcheck = true;*/ }
else { strcpy(dir,start); };
// Path found

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: drive_iso.cpp,v 1.7 2005-03-25 09:06:46 qbix79 Exp $ */
/* $Id: drive_iso.cpp,v 1.8 2005-07-19 19:45:31 qbix79 Exp $ */
#include <cctype>
#include <cstring>
@ -446,7 +446,7 @@ bool isoDrive :: lookup(isoDirEntry *de, const char *path)
if (!strcmp(path, "")) return true;
char isoPath[ISO_MAXPATHNAME];
strncpy(isoPath, path, ISO_MAXPATHNAME);
safe_strncpy(isoPath, path, ISO_MAXPATHNAME);
strreplace(isoPath, '\\', '/');
int beginPos = 0;
@ -456,8 +456,7 @@ bool isoDrive :: lookup(isoDirEntry *de, const char *path)
char name[38];
if (pos - beginPos >= 38) return false;
if (beginPos >= ISO_MAXPATHNAME) return false;
strncpy(name, &isoPath[beginPos], pos - beginPos);
name[pos - beginPos] = 0;
safe_strncpy(name, &isoPath[beginPos], pos - beginPos + 1);
beginPos = pos + 1;
if (!IS_DIR(de->fileFlags)) return false;
if (!lookupSingle(de, name, EXTENT_LOCATION(*de), DATA_LENGTH(*de))) return false;