summaryrefslogtreecommitdiffstats
path: root/cpukit/libfs
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2011-03-15 15:05:29 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2011-03-15 15:05:29 +0000
commit315c9b89f3292bb828451072eae866c51688f06a (patch)
tree290c3bbbf7772dd52ecbad9812d1cba957eb8860 /cpukit/libfs
parent2011-03-15 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-315c9b89f3292bb828451072eae866c51688f06a.tar.bz2
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.
Diffstat (limited to 'cpukit/libfs')
-rw-r--r--cpukit/libfs/src/dosfs/msdos_format.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/cpukit/libfs/src/dosfs/msdos_format.c b/cpukit/libfs/src/dosfs/msdos_format.c
index 71cd137f7e..1394f811c4 100644
--- a/cpukit/libfs/src/dosfs/msdos_format.c
+++ b/cpukit/libfs/src/dosfs/msdos_format.c
@@ -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;
}
@@ -925,19 +933,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
*/
if (ret_val == 0) {
@@ -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;