- fortify ASPI /proc file parsing (SCSI_getprocentry()) against

CD-ROM drives that are doing mad things with spaces
- add ERR()s in case of parsing problems
This commit is contained in:
Andreas Mohr 2000-11-07 20:26:14 +00:00 committed by Alexandre Julliard
parent e1bcb4f942
commit 365e7479f2

View file

@ -311,34 +311,52 @@ struct LinuxProcScsiDevice
int ansirev; int ansirev;
}; };
/*
* we need to declare white spaces explicitly via %*1[ ],
* as there are very dainbread CD-ROM devices out there
* which have their manufacturer name blanked out via spaces,
* which confuses fscanf's parsing (skips all blank spaces)
*/
static int static int
SCSI_getprocentry( FILE * procfile, struct LinuxProcScsiDevice * dev ) SCSI_getprocentry( FILE * procfile, struct LinuxProcScsiDevice * dev )
{ {
int result; int result;
result = fscanf( procfile, result = fscanf( procfile,
"Host: scsi%d Channel: %d Id: %d Lun: %d\n", "Host:%*1[ ]scsi%d%*1[ ]Channel:%*1[ ]%d%*1[ ]Id:%*1[ ]%d%*1[ ]Lun:%*1[ ]%d\n",
&dev->host, &dev->host,
&dev->channel, &dev->channel,
&dev->target, &dev->target,
&dev->lun ); &dev->lun );
if( result == EOF ) if( result == EOF )
{
/* "end of entries" return, so no TRACE() here */
return EOF; return EOF;
}
if( result != 4 ) if( result != 4 )
{
ERR("bus id line scan count error\n");
return 0; return 0;
}
result = fscanf( procfile, result = fscanf( procfile,
" Vendor: %8c Model: %16c Rev: %4c\n", " Vendor:%*1[ ]%8c%*1[ ]Model:%*1[ ]%16c%*1[ ]Rev:%*1[ ]%4c\n",
dev->vendor, dev->vendor,
dev->model, dev->model,
dev->rev ); dev->rev );
if( result != 3 ) if( result != 3 )
{
ERR("model line scan count error\n");
return 0; return 0;
}
result = fscanf( procfile, result = fscanf( procfile,
" Type: %32c ANSI SCSI revision: %d\n", " Type:%*3[ ]%32c%*1[ ]ANSI%*1[ ]SCSI%*1[ ]revision:%*1[ ]%d\n",
dev->type, dev->type,
&dev->ansirev ); &dev->ansirev );
if( result != 2 ) if( result != 2 )
{
ERR("SCSI type line scan count error\n");
return 0; return 0;
}
/* Since we fscanf with %XXc instead of %s.. put a NULL at end */ /* Since we fscanf with %XXc instead of %s.. put a NULL at end */
dev->vendor[8] = 0; dev->vendor[8] = 0;
dev->model[16] = 0; dev->model[16] = 0;