Use only safe string functions

This commit is contained in:
Sam Lantinga
2006-02-19 23:46:34 +00:00
parent b56a6d0212
commit 0ef73d9eae
60 changed files with 223 additions and 263 deletions

View File

@@ -124,12 +124,11 @@ static void AddDrive(char *drive, struct stat *stbuf)
/* Add this drive to our list */
i = SDL_numcds;
SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1);
SDL_cdlist[i] = SDL_strdup(drive);
if ( SDL_cdlist[i] == NULL ) {
SDL_OutOfMemory();
return;
}
SDL_strcpy(SDL_cdlist[i], drive);
SDL_cdmode[i] = stbuf->st_rdev;
++SDL_numcds;
#ifdef DEBUG_CDROM
@@ -302,9 +301,10 @@ int SDL_SYS_CDInit(void)
SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
if ( SDLcdrom != NULL ) {
char *cdpath, *delim;
cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1);
size_t len = SDL_strlen(SDLcdrom)+1;
cdpath = SDL_stack_alloc(char, len);
if ( cdpath != NULL ) {
SDL_strcpy(cdpath, SDLcdrom);
SDL_strlcpy(cdpath, SDLcdrom, len);
SDLcdrom = cdpath;
do {
delim = SDL_strchr(SDLcdrom, ':');
@@ -323,7 +323,7 @@ int SDL_SYS_CDInit(void)
SDLcdrom = NULL;
}
} while ( SDLcdrom );
SDL_free(cdpath);
SDL_stack_free(cdpath);
}
/* If we found our drives, there's nothing left to do */
@@ -360,21 +360,23 @@ static int SDL_SYS_CDOpen(int drive)
int fd;
char* lastsl;
char* cdromname;
size_t len;
/*
* We found /dev/cd? drives and that is in our list. But we can
* open only the /dev/rcd? versions of those devices for Audio CD.
*/
cdromname = (char*)SDL_malloc( SDL_strlen(SDL_cdlist[drive]+2) );
SDL_strcpy(cdromname,SDL_cdlist[drive]);
len = SDL_strlen(SDL_cdlist[drive])+2;
cdromname = (char*)SDL_malloc(len);
SDL_strlcpy(cdromname,SDL_cdlist[drive],len);
lastsl = SDL_strrchr(cdromname,'/');
if (lastsl) {
*lastsl = 0;
strcat(cdromname,"/r");
SDL_strlcat(cdromname,"/r",len);
lastsl = SDL_strrchr(SDL_cdlist[drive],'/');
if (lastsl) {
lastsl++;
strcat(cdromname,lastsl);
SDL_strlcat(cdromname,lastsl,len);
}
}

View File

@@ -224,12 +224,11 @@ static void AddDrive(char *drive, struct stat *stbuf)
/* Add this drive to our list */
i = SDL_numcds;
SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1);
SDL_cdlist[i] = SDL_strdup(drive);
if ( SDL_cdlist[i] == NULL ) {
SDL_OutOfMemory();
return;
}
SDL_strcpy(SDL_cdlist[i], drive);
SDL_cdmode[i] = stbuf->st_rdev;
++SDL_numcds;
#ifdef DEBUG_CDROM
@@ -265,9 +264,10 @@ int SDL_SYS_CDInit(void)
SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
if ( SDLcdrom != NULL ) {
char *cdpath, *delim;
cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1);
size_t len = SDL_strlen(SDLcdrom)+1;
cdpath = SDL_stack_alloc(char, len);
if ( cdpath != NULL ) {
SDL_strcpy(cdpath, SDLcdrom);
SDL_strlcpy(cdpath, SDLcdrom, len);
SDLcdrom = cdpath;
do {
delim = SDL_strchr(SDLcdrom, ':');
@@ -283,7 +283,7 @@ int SDL_SYS_CDInit(void)
SDLcdrom = NULL;
}
} while ( SDLcdrom );
SDL_free(cdpath);
SDL_stack_free(cdpath);
}
/* If we found our drives, there's nothing left to do */

View File

@@ -110,12 +110,11 @@ static void AddDrive(char *drive, struct stat *stbuf)
/* Add this drive to our list */
i = SDL_numcds;
SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1);
SDL_cdlist[i] = SDL_strdup(drive);
if ( SDL_cdlist[i] == NULL ) {
SDL_OutOfMemory();
return;
}
SDL_strcpy(SDL_cdlist[i], drive);
SDL_cdmode[i] = stbuf->st_rdev;
++SDL_numcds;
#ifdef DEBUG_CDROM
@@ -152,9 +151,10 @@ int SDL_SYS_CDInit(void)
SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
if ( SDLcdrom != NULL ) {
char *cdpath, *delim;
cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1);
size_t len = SDL_strlen(SDLcdrom)+1;
cdpath = SDL_stack_alloc(char, len);
if ( cdpath != NULL ) {
SDL_strcpy(cdpath, SDLcdrom);
SDL_strlcpy(cdpath, SDLcdrom, len);
SDLcdrom = cdpath;
do {
delim = SDL_strchr(SDLcdrom, ':');
@@ -170,7 +170,7 @@ int SDL_SYS_CDInit(void)
SDLcdrom = NULL;
}
} while ( SDLcdrom );
SDL_free(cdpath);
SDL_stack_free(cdpath);
}
/* If we found our drives, there's nothing left to do */

View File

@@ -167,12 +167,11 @@ static void AddDrive(char *drive, struct stat *stbuf)
/* Add this drive to our list */
i = SDL_numcds;
SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1);
SDL_cdlist[i] = SDL_strdup(drive);
if ( SDL_cdlist[i] == NULL ) {
SDL_OutOfMemory();
return;
}
SDL_strcpy(SDL_cdlist[i], drive);
SDL_cdmode[i] = stbuf->st_rdev;
++SDL_numcds;
#ifdef DEBUG_CDROM
@@ -192,21 +191,25 @@ static void CheckMounts(const char *mtab)
if ( mntfp != NULL ) {
char *tmp;
char *mnt_type;
size_t mnt_type_len;
char *mnt_dev;
size_t mnt_dev_len;
while ( (mntent=getmntent(mntfp)) != NULL ) {
mnt_type = SDL_malloc(SDL_strlen(mntent->mnt_type) + 1);
mnt_type_len = SDL_strlen(mntent->mnt_type) + 1;
mnt_type = SDL_stack_alloc(char, mnt_type_len);
if (mnt_type == NULL)
continue; /* maybe you'll get lucky next time. */
mnt_dev = SDL_malloc(SDL_strlen(mntent->mnt_fsname) + 1);
mnt_dev_len = SDL_strlen(mntent->mnt_fsname) + 1;
mnt_dev = SDL_stack_alloc(char, mnt_dev_len);
if (mnt_dev == NULL) {
SDL_free(mnt_type);
SDL_stack_free(mnt_type);
continue;
}
SDL_strcpy(mnt_type, mntent->mnt_type);
SDL_strcpy(mnt_dev, mntent->mnt_fsname);
SDL_strlcpy(mnt_type, mntent->mnt_type, mnt_type_len);
SDL_strlcpy(mnt_dev, mntent->mnt_fsname, mnt_dev_len);
/* Handle "supermount" filesystem mounts */
if ( SDL_strcmp(mnt_type, MNTTYPE_SUPER) == 0 ) {
@@ -242,8 +245,8 @@ static void CheckMounts(const char *mtab)
AddDrive(mnt_dev, &stbuf);
}
}
SDL_free(mnt_dev);
SDL_free(mnt_type);
SDL_stack_free(mnt_dev);
SDL_stack_free(mnt_type);
}
endmntent(mntfp);
}
@@ -277,9 +280,10 @@ int SDL_SYS_CDInit(void)
SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
if ( SDLcdrom != NULL ) {
char *cdpath, *delim;
cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1);
size_t len = SDL_strlen(SDLcdrom)+1;
cdpath = SDL_stack_alloc(char, len);
if ( cdpath != NULL ) {
SDL_strcpy(cdpath, SDLcdrom);
SDL_strlcpy(cdpath, SDLcdrom, len);
SDLcdrom = cdpath;
do {
delim = SDL_strchr(SDLcdrom, ':');
@@ -298,7 +302,7 @@ int SDL_SYS_CDInit(void)
SDLcdrom = NULL;
}
} while ( SDLcdrom );
SDL_free(cdpath);
SDL_stack_free(cdpath);
}
/* If we found our drives, there's nothing left to do */

View File

@@ -115,12 +115,11 @@ static void AddDrive(char *drive, struct stat *stbuf)
/* Add this drive to our list */
i = SDL_numcds;
SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1);
SDL_cdlist[i] = SDL_strdup(drive);
if ( SDL_cdlist[i] == NULL ) {
SDL_OutOfMemory();
return;
}
SDL_strcpy(SDL_cdlist[i], drive);
SDL_cdmode[i] = stbuf->st_rdev;
++SDL_numcds;
#ifdef DEBUG_CDROM
@@ -161,9 +160,10 @@ int SDL_SYS_CDInit(void)
SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
if ( SDLcdrom != NULL ) {
char *cdpath, *delim;
cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1);
size_t len = SDL_strlen(SDLcdrom)+1;
cdpath = SDL_stack_alloc(char, len);
if ( cdpath != NULL ) {
SDL_strcpy(cdpath, SDLcdrom);
SDL_strlcpy(cdpath, SDLcdrom, len);
SDLcdrom = cdpath;
do {
delim = SDL_strchr(SDLcdrom, ':');
@@ -179,7 +179,7 @@ int SDL_SYS_CDInit(void)
SDLcdrom = NULL;
}
} while ( SDLcdrom );
SDL_free(cdpath);
SDL_stack_free(cdpath);
}
/* If we found our drives, there's nothing left to do */

View File

@@ -94,13 +94,12 @@ for (i=0; i<SDL_numcds; i++)
{
msp.ulNumber = i+1;
mciSendCommand(0,MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_WAIT,&msp, 0);
SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(SysInfoRet)+1);
SDL_cdlist[i] = SDL_strdup(SysInfoRet);
if ( SDL_cdlist[i] == NULL )
{
SDL_OutOfMemory();
return(-1);
}
SDL_strcpy(SDL_cdlist[i], SysInfoRet);
}
return(0);
}

View File

@@ -119,13 +119,11 @@ static void AddDrive(char *drive, struct stat *stbuf)
/* Add this drive to our list */
i = SDL_numcds;
SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1);
SDL_cdlist[i] = SDL_strdup(drive);
if ( SDL_cdlist[i] == NULL ) {
SDL_OutOfMemory();
return;
}
SDL_strcpy(SDL_cdlist[i], drive);
SDL_cdmode[i] = stbuf->st_rdev;
++SDL_numcds;
#ifdef DEBUG_CDROM
@@ -174,9 +172,10 @@ int SDL_SYS_CDInit(void)
SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
if ( SDLcdrom != NULL ) {
char *cdpath, *delim;
cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1);
size_t len = SDL_strlen(SDLcdrom)+1;
cdpath = SDL_stack_alloc(len);
if ( cdpath != NULL ) {
SDL_strcpy(cdpath, SDLcdrom);
SDL_strlcpy(cdpath, SDLcdrom, len);
SDLcdrom = cdpath;
do {
delim = SDL_strchr(SDLcdrom, ':');
@@ -192,7 +191,7 @@ int SDL_SYS_CDInit(void)
SDLcdrom = NULL;
}
} while ( SDLcdrom );
SDL_free(cdpath);
SDL_stack_free(cdpath);
}
/* If we found our drives, there's nothing left to do */
@@ -226,15 +225,6 @@ int SDL_SYS_CDInit(void)
#endif
}
}
/*
SDLcdrom=SDL_malloc(sizeof(char) * 32);
SDL_strcpy(SDLcdrom,"/dev/rdisk/cdrom0c");
SDL_cdlist[0] = SDLcdrom;
stat(SDLcdrom, &stbuf);
SDL_cdmode[0] = stbuf.st_rdev;
SDL_numcds = 1;
*/
return (0);
}

View File

@@ -124,13 +124,12 @@ static void AddDrive(char *drive, struct stat *stbuf)
/* Add this drive to our list */
i = SDL_numcds;
SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1);
SDL_cdlist[i] = SDL_strdup(drive);
if (SDL_cdlist[i] == NULL)
{
SDL_OutOfMemory();
return;
}
SDL_strcpy(SDL_cdlist[i], drive);
SDL_cdmode[i] = stbuf->st_rdev;
++SDL_numcds;
}
@@ -169,11 +168,11 @@ int SDL_SYS_CDInit(void)
if ( SDLcdrom != NULL )
{
char *cdpath, *delim;
cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1);
size_t len = SDL_strlen(SDLcdrom)+1;
cdpath = SDL_stack_alloc(len);
if (cdpath != NULL)
{
SDL_strcpy(cdpath, SDLcdrom);
SDL_strlcpy(cdpath, SDLcdrom, len);
SDLcdrom = cdpath;
do {
delim = SDL_strchr(SDLcdrom, ':');
@@ -194,7 +193,7 @@ int SDL_SYS_CDInit(void)
SDLcdrom = NULL;
}
} while (SDLcdrom);
SDL_free(cdpath);
SDL_stack_free(cdpath);
}
/* If we found our drives, there's nothing left to do */

View File

@@ -63,12 +63,11 @@ static void AddDrive(char *drive)
if ( SDL_numcds < MAX_DRIVES ) {
/* Add this drive to our list */
i = SDL_numcds;
SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1);
SDL_cdlist[i] = SDL_strdup(drive);
if ( SDL_cdlist[i] == NULL ) {
SDL_OutOfMemory();
return;
}
SDL_strcpy(SDL_cdlist[i], drive);
++SDL_numcds;
#ifdef CDROM_DEBUG
fprintf(stderr, "Added CD-ROM drive: %s\n", drive);