Mercurial > sdl-ios-xcode
comparison src/cdrom/linux/SDL_syscdrom.c @ 139:ef23a1bf1244
Fixed potential buffer overflow in Linux CD code (thanks Ryan!)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 09 Aug 2001 05:34:17 +0000 |
parents | 74212992fb08 |
children | b0f09f86378d |
comparison
equal
deleted
inserted
replaced
138:69ee0b88b615 | 139:ef23a1bf1244 |
---|---|
179 struct mntent *mntent; | 179 struct mntent *mntent; |
180 struct stat stbuf; | 180 struct stat stbuf; |
181 | 181 |
182 mntfp = setmntent(mtab, "r"); | 182 mntfp = setmntent(mtab, "r"); |
183 if ( mntfp != NULL ) { | 183 if ( mntfp != NULL ) { |
184 char *tmp, mnt_type[32], mnt_dev[1024]; | 184 char *tmp; |
185 char *mnt_type; | |
186 char *mnt_dev; | |
185 | 187 |
186 while ( (mntent=getmntent(mntfp)) != NULL ) { | 188 while ( (mntent=getmntent(mntfp)) != NULL ) { |
187 /* Warning, possible buffer overflow.. */ | 189 mnt_type = malloc(strlen(mntent->mnt_type) + 1); |
190 if (mnt_type == NULL) | |
191 continue; /* maybe you'll get lucky next time. */ | |
192 | |
193 mnt_dev = malloc(strlen(mntent->mnt_fsname) + 1); | |
194 if (mnt_dev == NULL) { | |
195 free(mnt_type); | |
196 continue; | |
197 } | |
198 | |
188 strcpy(mnt_type, mntent->mnt_type); | 199 strcpy(mnt_type, mntent->mnt_type); |
189 strcpy(mnt_dev, mntent->mnt_fsname); | 200 strcpy(mnt_dev, mntent->mnt_fsname); |
190 | 201 |
191 /* Handle "supermount" filesystem mounts */ | 202 /* Handle "supermount" filesystem mounts */ |
192 if ( strcmp(mnt_type, MNTTYPE_SUPER) == 0 ) { | 203 if ( strcmp(mnt_type, MNTTYPE_SUPER) == 0 ) { |
214 #endif | 225 #endif |
215 if (CheckDrive(mnt_dev, mnt_type, &stbuf) > 0) { | 226 if (CheckDrive(mnt_dev, mnt_type, &stbuf) > 0) { |
216 AddDrive(mnt_dev, &stbuf); | 227 AddDrive(mnt_dev, &stbuf); |
217 } | 228 } |
218 } | 229 } |
230 free(mnt_dev); | |
231 free(mnt_type); | |
219 } | 232 } |
220 endmntent(mntfp); | 233 endmntent(mntfp); |
221 } | 234 } |
222 } | 235 } |
223 #endif /* USE_MNTENT */ | 236 #endif /* USE_MNTENT */ |