Skip to content

Commit 39a903b

Browse files
Merge pull request #9549 from embhorn/zd20965
Fix MQX example null deref
2 parents 16e035d + d5691fe commit 39a903b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

mqx/util_lib/Sources/util.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ int sdcard_open(MQX_FILE_PTR *com_handle, MQX_FILE_PTR *sdcard_handle,
8888
/* Open partition manager */
8989
*partman_handle = fopen(partman_name, NULL);
9090
if (*partman_handle == NULL) {
91-
error_code = ferror(*partman_handle);
92-
printf("Error opening partition manager: %s\n", MFS_Error_text(
93-
(uint32_t) error_code));
91+
printf("Error opening partition manager\n");
9492
return -64;
9593
}
9694

@@ -119,15 +117,19 @@ int sdcard_open(MQX_FILE_PTR *com_handle, MQX_FILE_PTR *sdcard_handle,
119117

120118
/* Open file system */
121119
*filesystem_handle = fopen(filesystem_name, NULL);
120+
if (*filesystem_handle == NULL) {
121+
printf("Error opening filesystem.\n");
122+
return -67;
123+
}
122124
error_code = ferror(*filesystem_handle);
123125
if ((error_code != MFS_NO_ERROR) && (error_code != MFS_NOT_A_DOS_DISK)) {
124126
printf("Error opening filesystem: %s\n", MFS_Error_text(
125127
(uint32_t) error_code));
126-
return -67;
128+
return -68;
127129
}
128130
if (error_code == MFS_NOT_A_DOS_DISK) {
129131
printf("NOT A DOS DISK! You must format to continue.\n");
130-
return -68;
132+
return -69;
131133
}
132134

133135
return 0;

0 commit comments

Comments
 (0)