I thought, that this may be useful to somebody ... If this patch
were here before it would save me a few hours searching why every
program hanged on commdlg open/save file dialogs ...
I'm sending it here because I'm not sure whether I should be more/less
paranoid and stat() the file before open() or not, or even if this
check really should go into this function.
Decide. ;)
Changelog: [MQ] Add check for block device in DRIVE_ReadSuperblock
Index: files/drive.c
===================================================================
RCS file: /home/wine/wine/files/drive.c,v
retrieving revision 1.83
diff -u -r1.83 drive.c
--- files/drive.c 13 Jan 2003 20:44:13 -0000 1.83
+++ files/drive.c 18 Jan 2003 02:05:38 -0000
@@ -623,20 +623,36 @@
int fd;
off_t offs;
int ret = 0;
+ struct stat stat_buf;
if (memset(buff,0,DRIVE_SUPER)!=buff) return -1;
if ((fd=open(DOSDrives[drive].device,O_RDONLY)) == -1)
{
- struct stat st;
if (!DOSDrives[drive].device)
ERR("No device configured for drive %c: !\n", 'A'+drive);
else
ERR("Couldn't open device '%s' for drive %c: ! (%s)\n", DOSDrives[drive].device, 'A'+drive,
- (stat(DOSDrives[drive].device, &st)) ?
+ (stat(DOSDrives[drive].device, &stat_buf)) ?
"not available or symlink not valid ?" : "no permission");
ERR("Can't read drive volume info ! Either pre-set it or make sure the device to read it from is accessible !\n");
PROFILE_UsageWineIni();
return -1;
+ }
+
+ /* MQ: I guess, we don't have to merge this call with the one above - some weird user
+ may try to swap the file before stat() and open() while we're not watching ;)
+ OTOH if we open FIFO we're stuck anyway, so FIXME */
+ if (fstat(fd, &stat_buf) < 0) { /* shouldn't happen since we just opened that file */
+ ERR("fstat() failed for opened device '%s' (drive %c:) ! IT SHOULDN'T HAPPEN !!!\n",
+ DOSDrives[drive].device, 'A'+drive);
+ ret = -1;
+ goto the_end;
+ }
+ if (!S_ISBLK(stat_buf.st_mode)) {
+ ERR("Device '%s' (drive %c:) is not a block device - check your config\n",
+ DOSDrives[drive].device, 'A'+drive);
+ ret = -1;
+ goto the_end;
}
switch(DOSDrives[drive].type)