comparison src/cdrom/linux/SDL_syscdrom.c @ 1379:c0a74f199ecf

Use only safe string functions
author Sam Lantinga <slouken@libsdl.org>
date Sun, 19 Feb 2006 23:46:34 +0000
parents 19418e4422cb
children d910939febfa
comparison
equal deleted inserted replaced
1378:dc0e13e7e1ae 1379:c0a74f199ecf
165 } 165 }
166 } 166 }
167 167
168 /* Add this drive to our list */ 168 /* Add this drive to our list */
169 i = SDL_numcds; 169 i = SDL_numcds;
170 SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1); 170 SDL_cdlist[i] = SDL_strdup(drive);
171 if ( SDL_cdlist[i] == NULL ) { 171 if ( SDL_cdlist[i] == NULL ) {
172 SDL_OutOfMemory(); 172 SDL_OutOfMemory();
173 return; 173 return;
174 } 174 }
175 SDL_strcpy(SDL_cdlist[i], drive);
176 SDL_cdmode[i] = stbuf->st_rdev; 175 SDL_cdmode[i] = stbuf->st_rdev;
177 ++SDL_numcds; 176 ++SDL_numcds;
178 #ifdef DEBUG_CDROM 177 #ifdef DEBUG_CDROM
179 fprintf(stderr, "Added CD-ROM drive: %s\n", drive); 178 fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
180 #endif 179 #endif
190 189
191 mntfp = setmntent(mtab, "r"); 190 mntfp = setmntent(mtab, "r");
192 if ( mntfp != NULL ) { 191 if ( mntfp != NULL ) {
193 char *tmp; 192 char *tmp;
194 char *mnt_type; 193 char *mnt_type;
194 size_t mnt_type_len;
195 char *mnt_dev; 195 char *mnt_dev;
196 size_t mnt_dev_len;
196 197
197 while ( (mntent=getmntent(mntfp)) != NULL ) { 198 while ( (mntent=getmntent(mntfp)) != NULL ) {
198 mnt_type = SDL_malloc(SDL_strlen(mntent->mnt_type) + 1); 199 mnt_type_len = SDL_strlen(mntent->mnt_type) + 1;
200 mnt_type = SDL_stack_alloc(char, mnt_type_len);
199 if (mnt_type == NULL) 201 if (mnt_type == NULL)
200 continue; /* maybe you'll get lucky next time. */ 202 continue; /* maybe you'll get lucky next time. */
201 203
202 mnt_dev = SDL_malloc(SDL_strlen(mntent->mnt_fsname) + 1); 204 mnt_dev_len = SDL_strlen(mntent->mnt_fsname) + 1;
205 mnt_dev = SDL_stack_alloc(char, mnt_dev_len);
203 if (mnt_dev == NULL) { 206 if (mnt_dev == NULL) {
204 SDL_free(mnt_type); 207 SDL_stack_free(mnt_type);
205 continue; 208 continue;
206 } 209 }
207 210
208 SDL_strcpy(mnt_type, mntent->mnt_type); 211 SDL_strlcpy(mnt_type, mntent->mnt_type, mnt_type_len);
209 SDL_strcpy(mnt_dev, mntent->mnt_fsname); 212 SDL_strlcpy(mnt_dev, mntent->mnt_fsname, mnt_dev_len);
210 213
211 /* Handle "supermount" filesystem mounts */ 214 /* Handle "supermount" filesystem mounts */
212 if ( SDL_strcmp(mnt_type, MNTTYPE_SUPER) == 0 ) { 215 if ( SDL_strcmp(mnt_type, MNTTYPE_SUPER) == 0 ) {
213 tmp = SDL_strstr(mntent->mnt_opts, "fs="); 216 tmp = SDL_strstr(mntent->mnt_opts, "fs=");
214 if ( tmp ) { 217 if ( tmp ) {
240 #endif 243 #endif
241 if (CheckDrive(mnt_dev, mnt_type, &stbuf) > 0) { 244 if (CheckDrive(mnt_dev, mnt_type, &stbuf) > 0) {
242 AddDrive(mnt_dev, &stbuf); 245 AddDrive(mnt_dev, &stbuf);
243 } 246 }
244 } 247 }
245 SDL_free(mnt_dev); 248 SDL_stack_free(mnt_dev);
246 SDL_free(mnt_type); 249 SDL_stack_free(mnt_type);
247 } 250 }
248 endmntent(mntfp); 251 endmntent(mntfp);
249 } 252 }
250 } 253 }
251 #endif /* USE_MNTENT */ 254 #endif /* USE_MNTENT */
275 278
276 /* Look in the environment for our CD-ROM drive list */ 279 /* Look in the environment for our CD-ROM drive list */
277 SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ 280 SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
278 if ( SDLcdrom != NULL ) { 281 if ( SDLcdrom != NULL ) {
279 char *cdpath, *delim; 282 char *cdpath, *delim;
280 cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1); 283 size_t len = SDL_strlen(SDLcdrom)+1;
284 cdpath = SDL_stack_alloc(char, len);
281 if ( cdpath != NULL ) { 285 if ( cdpath != NULL ) {
282 SDL_strcpy(cdpath, SDLcdrom); 286 SDL_strlcpy(cdpath, SDLcdrom, len);
283 SDLcdrom = cdpath; 287 SDLcdrom = cdpath;
284 do { 288 do {
285 delim = SDL_strchr(SDLcdrom, ':'); 289 delim = SDL_strchr(SDLcdrom, ':');
286 if ( delim ) { 290 if ( delim ) {
287 *delim++ = '\0'; 291 *delim++ = '\0';
296 SDLcdrom = delim; 300 SDLcdrom = delim;
297 } else { 301 } else {
298 SDLcdrom = NULL; 302 SDLcdrom = NULL;
299 } 303 }
300 } while ( SDLcdrom ); 304 } while ( SDLcdrom );
301 SDL_free(cdpath); 305 SDL_stack_free(cdpath);
302 } 306 }
303 307
304 /* If we found our drives, there's nothing left to do */ 308 /* If we found our drives, there's nothing left to do */
305 if ( SDL_numcds > 0 ) { 309 if ( SDL_numcds > 0 ) {
306 return(0); 310 return(0);