Part Number: CC2538
Other Parts Discussed in Thread: Z-STACK
Hi,
I'm a PhD student and currently learning ZCL APIs. Recently I got some memory crash when sending some valid ZCL messages. I use IAR workbench and its simulator and CC2538 with SmartRF06 evaluation board for study.
1. zclParseInDiscCmdsRspCmd( zclParseCmd_t *pCmd )
The ZCL message I construct is \x00\x01\x12\x00\x00 which means the frame control is 0, transaction sequence number is 1, the command ID is 0x12 that is Discover Commands Received Response. Discovery complete is 0 and command identifier is 0. All the fields are based on ZCL Spec.
In simulator, I just initialize the memory and required system variable. Then I create an afIncomingMSGPacket_t variable with such message and pass it to zcl_ProcessMessageMSG() which will trigger zclParseInDiscComdsRspCmd(). Then I got memory crash at line of code 4348, pDiscoverRspCmd->pCmdID[i] = *pBuf++. When I use IAR to debug step by step I see the following value:
The crash message says read outside range 0xCDCDCDCD. The variable pCmdID is an array pointer, I think when it's allocated memory, its value should be a valid memory address which I guess should be 0x20043DC in this case. However, the result shows it's not initialized when allocated memory space with structure variable pDiscoverRspCmd.
Also, I send the same message with zcl_SendCommand() on CC2538 as coordinator. And the end device which is also CC2538 receives message and pass ZCL to handle. The end device then freezes. When I debug on device, I also see the similar value. The address 0xFFFF0004 is outside RAM section.
I think there may some issues with ZCL memory allocation. Could anyone please help verify if this is bug or vulnerability?
2. zclProcessInWriteCmd(zclIncoming_t *pInMsg)
For this API call, I think there is a NullPointerReference. The variable writeRspCmd is only initialized when commandID is ZCL_CMD_WRITE. However, this function is also process command ZCL_CMD_WRITE_NO_RSP. When it's a NO_RSP command, this variable is a null pointer. However, line of code 4513 directly uses it to write a value. When I run codes in simulator, it crashes and shows me the address is outside range which I think it's correct. However, on CC2538 it has no issues which I think could be wrong.
On CC2538 I send the following message \x08\x01\x05\x00\x00\x00\x00, where frame control is 0x08, tranSeqNum is 0x01, commandID is 0x05. The payload is a write attribute record where the identifier is 0x0000, data type is 0x00, and attribute data is 0x00. When I debug on both simulator and CC2538, I see the values of writeRspCmd as the following. Based on my understanding, the code should not write to attrList since 0x0000002 is ROM section and read only. The device should crash in this case. However, it executes without any issues.
Could anyone please help me verify these two issue if they are bugs? Or if I did in wrong way? Thank you so much!





