2011-03-15 Joel Sherrill <joel.sherrill@oarcorp.com>

* libfs/src/dosfs/msdos_format.c: Address Coverity issue 183 which was
	where an expression evaluated to a constant and issue 185 which was a
	potential (although unlikely in expected usage) time-of-check,
	time-of-use race condition.
This commit is contained in:
Joel Sherrill
2011-03-15 15:05:29 +00:00
parent d252351c43
commit 315c9b89f3
2 changed files with 23 additions and 19 deletions
+7
View File
@@ -1,3 +1,10 @@
2011-03-15 Joel Sherrill <joel.sherrill@oarcorp.com>
* libfs/src/dosfs/msdos_format.c: Address Coverity issue 183 which was
where an expression evaluated to a constant and issue 185 which was a
potential (although unlikely in expected usage) time-of-check,
time-of-use race condition.
2011-03-15 Joel Sherrill <joel.sherrill@oarcorp.com>
* libmisc/shell/main_setenv.c: Address Coverity issue 134 which
+16 -19
View File
@@ -896,21 +896,29 @@ int msdos_format
int i;
msdos_format_param_t fmt_params;
msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_INFO,
"formating: %s\n", devname);
/*
* open device for writing
*/
msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_DETAIL, "open device\n");
fd = open(devname, O_RDWR);
if (fd == -1) {
ret_val= -1;
}
/*
* sanity check on device
*/
msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_DETAIL,
"stat check: %s\n", devname);
if (ret_val == 0) {
rc = stat(devname, &stat_buf);
rc = fstat(fd, &stat_buf);
ret_val = rc;
}
msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_INFO,
"formating: %s\n", devname);
/* rtems feature: no block devices, all are character devices */
if ((ret_val == 0) &&
(!S_ISBLK(stat_buf.st_mode))) {
if ((ret_val == 0) && (!S_ISBLK(stat_buf.st_mode))) {
errno = ENOTTY;
ret_val = -1;
}
@@ -924,19 +932,6 @@ int msdos_format
}
}
/*
* open device for writing
*/
if (ret_val == 0) {
msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_DETAIL,
"open device\n");
fd = open(devname, O_RDWR);
if (fd == -1)
{
ret_val= -1;
}
}
/*
* compute formatting parameters
*/
@@ -957,6 +952,7 @@ int msdos_format
fmt_params.bytes_per_sector,
0xe5);
}
/*
* create master boot record
*/
@@ -1080,7 +1076,8 @@ int msdos_format
case FAT_FAT16:
/* FAT entry 0: 0xff00|media_type */
FAT_SET_VAL16(tmp_sec,0,0xff00|fmt_params.media_code);
FAT_SET_VAL8(tmp_sec,0,fmt_params.media_code);
FAT_SET_VAL8(tmp_sec,1,0xff);
/* FAT entry 1: EOC */
FAT_SET_VAL16(tmp_sec,2,FAT_FAT16_EOC);
break;