@@ -60,18 +60,26 @@ void TPM2_Packet_U64ToByteArray(UINT64 val, BYTE* b)
6060 }
6161}
6262
63- /* Big-endian byte-array load helpers */
63+ /* Big-endian byte-array load helpers. Mirror the NULL-guard convention of the
64+ * U*ToByteArray store helpers above so callers get 0 for a NULL input rather
65+ * than a crash. */
6466UINT16 TPM2_Packet_ByteArrayToU16 (const BYTE * b )
6567{
68+ if (b == NULL )
69+ return 0 ;
6670 return (UINT16 )(((UINT16 )b [0 ] << 8 ) | b [1 ]);
6771}
6872UINT32 TPM2_Packet_ByteArrayToU32 (const BYTE * b )
6973{
74+ if (b == NULL )
75+ return 0 ;
7076 return ((UINT32 )b [0 ] << 24 ) | ((UINT32 )b [1 ] << 16 ) |
7177 ((UINT32 )b [2 ] << 8 ) | b [3 ];
7278}
7379UINT64 TPM2_Packet_ByteArrayToU64 (const BYTE * b )
7480{
81+ if (b == NULL )
82+ return 0 ;
7583 return ((UINT64 )b [0 ] << 56 ) | ((UINT64 )b [1 ] << 48 ) |
7684 ((UINT64 )b [2 ] << 40 ) | ((UINT64 )b [3 ] << 32 ) |
7785 ((UINT64 )b [4 ] << 24 ) | ((UINT64 )b [5 ] << 16 ) |
@@ -258,7 +266,9 @@ void TPM2_Packet_ParseBytes(TPM2_Packet* packet, byte* buf, int size)
258266void TPM2_Packet_ParseU16Buf (TPM2_Packet * packet , UINT16 * size , byte * buf ,
259267 UINT16 maxBufSz )
260268{
261- UINT16 wireSize ;
269+ /* Init to 0 so a NULL packet (TPM2_Packet_ParseU16 is a no-op in that
270+ * case) leaves wireSize well-defined for the arithmetic below. */
271+ UINT16 wireSize = 0 ;
262272 UINT16 copySz ;
263273
264274 TPM2_Packet_ParseU16 (packet , & wireSize );
@@ -809,6 +819,9 @@ TPM_RC TPM2_Packet_ParseSensitiveCreate(TPM2_Packet* packet, int maxSize,
809819 UINT16 dataSz = 0 ;
810820 int sensStartPos ;
811821
822+ if (packet == NULL || userAuth == NULL ) {
823+ return BAD_FUNC_ARG ;
824+ }
812825 if (packet -> pos + 2 > maxSize ) {
813826 rc = TPM_RC_COMMAND_SIZE ;
814827 }
0 commit comments