Skip to content

Commit 7850d9f

Browse files
committed
add inquiry check length
1 parent cfdd55c commit 7850d9f

File tree

3 files changed

+116
-92
lines changed

3 files changed

+116
-92
lines changed

common/usbx_device_classes/inc/ux_device_class_storage.h

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/***************************************************************************
2-
* Copyright (c) 2024 Microsoft Corporation
3-
*
2+
* Copyright (c) 2024 Microsoft Corporation
3+
*
44
* This program and the accompanying materials are made available under the
55
* terms of the MIT License which is available at
66
* https://opensource.org/licenses/MIT.
7-
*
7+
*
88
* SPDX-License-Identifier: MIT
99
**************************************************************************/
1010

@@ -67,15 +67,15 @@
6767
#ifndef UX_DEVICE_CLASS_STORAGE_H
6868
#define UX_DEVICE_CLASS_STORAGE_H
6969

70-
/* Determine if a C++ compiler is being used. If so, ensure that standard
71-
C is used to process the API information. */
70+
/* Determine if a C++ compiler is being used. If so, ensure that standard
71+
C is used to process the API information. */
7272

73-
#ifdef __cplusplus
73+
#ifdef __cplusplus
7474

75-
/* Yes, C++ compiler is present. Use standard C. */
76-
extern "C" {
75+
/* Yes, C++ compiler is present. Use standard C. */
76+
extern "C" {
7777

78-
#endif
78+
#endif
7979

8080

8181
/* Internal option: enable the basic USBX error checking. This define is typically used
@@ -192,6 +192,13 @@ extern "C" {
192192
#define UX_SLAVE_CLASS_STORAGE_INQUIRY_RESPONSE_LENGTH 36
193193
#define UX_SLAVE_CLASS_STORAGE_INQUIRY_RESPONSE_LENGTH_CD_ROM 0x5b
194194

195+
/* Define Storage Class SCSI inquiry response length constants. */
196+
197+
#define UX_SLAVE_CLASS_STORAGE_INQUIRY_RESPONSE_VENDOR_ID_LENGTH 0x08U
198+
#define UX_SLAVE_CLASS_STORAGE_INQUIRY_RESPONSE_PRODUCT_ID_LENGTH 0x10U
199+
#define UX_SLAVE_CLASS_STORAGE_INQUIRY_RESPONSE_PRODUCT_REVISION_LENGTH 0x04U
200+
#define UX_SLAVE_CLASS_STORAGE_INQUIRY_RESPONSE_PRODUCT_SERIAL_LENGTH 0x14U
201+
195202

196203
/* Define Storage Class SCSI start/stop command constants. */
197204

@@ -674,10 +681,10 @@ UINT _uxe_device_class_storage_initialize(UX_SLAVE_CLASS_COMMAND *command);
674681

675682
#define ux_device_class_storage_entry _ux_device_class_storage_entry
676683

677-
/* Determine if a C++ compiler is being used. If so, complete the standard
678-
C conditional started above. */
684+
/* Determine if a C++ compiler is being used. If so, complete the standard
685+
C conditional started above. */
679686
#ifdef __cplusplus
680-
}
681-
#endif
687+
}
688+
#endif
682689

683690
#endif

common/usbx_device_classes/src/ux_device_class_storage_initialize.c

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/***************************************************************************
2-
* Copyright (c) 2024 Microsoft Corporation
3-
*
2+
* Copyright (c) 2024 Microsoft Corporation
3+
*
44
* This program and the accompanying materials are made available under the
55
* terms of the MIT License which is available at
66
* https://opensource.org/licenses/MIT.
7-
*
7+
*
88
* SPDX-License-Identifier: MIT
99
**************************************************************************/
1010

@@ -30,10 +30,10 @@
3030

3131
/* Define the Slave Storage Class Inquiry data : DO NOT CHANGE THE LENGTH OF THESE ITEMS */
3232

33-
UCHAR _ux_system_slave_class_storage_vendor_id[] = "AzureRTO";
34-
UCHAR _ux_system_slave_class_storage_product_id[] = "USBX storage dev";
35-
UCHAR _ux_system_slave_class_storage_product_rev[] = "2000";
36-
UCHAR _ux_system_slave_class_storage_product_serial[] = "12345678901234567890";
33+
UCHAR _ux_system_slave_class_storage_vendor_id[] = "Eclipse ";
34+
UCHAR _ux_system_slave_class_storage_product_id[] = "USBX STORAGE DEV";
35+
UCHAR _ux_system_slave_class_storage_product_rev[] = "2000";
36+
UCHAR _ux_system_slave_class_storage_product_serial[] = "12345678901234567890";
3737

3838
/**************************************************************************/
3939
/* */
@@ -242,7 +242,7 @@ ULONG lun_index;
242242
return(status);
243243
}
244244

245-
245+
#ifdef UX_ENABLE_ERROR_CHECKING
246246
/**************************************************************************/
247247
/* */
248248
/* FUNCTION RELEASE */
@@ -292,18 +292,25 @@ UINT i;
292292
/* Sanity checks. */
293293
if (storage_parameter -> ux_slave_class_storage_parameter_number_lun > UX_MAX_SLAVE_LUN)
294294
return(UX_INVALID_PARAMETER);
295+
296+
if ((storage_parameter -> ux_slave_class_storage_parameter_vendor_id != UX_NULL)
297+
&& (( _ux_utility_string_length_get(storage_parameter -> ux_slave_class_storage_parameter_vendor_id) != 8))
298+
|| ((storage_parameter -> ux_slave_class_storage_parameter_product_id != UX_NULL)
299+
&& ( _ux_utility_string_length_get(storage_parameter -> ux_slave_class_storage_parameter_product_id) != 16))
300+
|| ((storage_parameter -> ux_slave_class_storage_parameter_product_rev != UX_NULL)
301+
&& ( _ux_utility_string_length_get(storage_parameter -> ux_slave_class_storage_parameter_product_rev) != 4))
302+
|| ((storage_parameter -> ux_slave_class_storage_parameter_product_serial != UX_NULL)
303+
&& ( _ux_utility_string_length_get(storage_parameter -> ux_slave_class_storage_parameter_product_serial) != 20)))
304+
return(UX_INVALID_PARAMETER);
305+
295306
for (i = 0; i < storage_parameter -> ux_slave_class_storage_parameter_number_lun; i ++)
296307
{
297-
if ((storage_parameter -> ux_slave_class_storage_parameter_lun[i].
298-
ux_slave_class_storage_media_read == UX_NULL) ||
299-
(storage_parameter -> ux_slave_class_storage_parameter_lun[i].
300-
ux_slave_class_storage_media_write == UX_NULL) ||
301-
(storage_parameter -> ux_slave_class_storage_parameter_lun[i].
302-
ux_slave_class_storage_media_status == UX_NULL)
308+
if ((storage_parameter -> ux_slave_class_storage_parameter_lun[i].ux_slave_class_storage_media_read == UX_NULL)
309+
|| (storage_parameter -> ux_slave_class_storage_parameter_lun[i].ux_slave_class_storage_media_write == UX_NULL)
310+
|| (storage_parameter -> ux_slave_class_storage_parameter_lun[i].ux_slave_class_storage_media_status == UX_NULL)
303311
#if defined(UX_SLAVE_CLASS_STORAGE_INCLUDE_MMC)
304-
|| (storage_parameter -> ux_slave_class_storage_parameter_lun[i].
305-
ux_slave_class_storage_media_notification == UX_NULL)
306-
#endif
312+
|| (storage_parameter -> ux_slave_class_storage_parameter_lun[i].ux_slave_class_storage_media_notification == UX_NULL)
313+
#endif /* UX_SLAVE_CLASS_STORAGE_INCLUDE_MMC */
307314
)
308315
{
309316
return(UX_INVALID_PARAMETER);
@@ -313,3 +320,4 @@ UINT i;
313320
/* Invoke storage initialize function. */
314321
return(_ux_device_class_storage_initialize(command));
315322
}
323+
#endif /* UX_ENABLE_ERROR_CHECKING */

0 commit comments

Comments
 (0)