Fixed the issue of incorrect DLT message parsing when payload length is 0 && Fixed potential wild pointers and improper memory free.

This commit is contained in:
LuChiChick 2026-04-23 10:58:12 +08:00
parent ce6f9646c4
commit 923ba12ae9

View File

@ -35,7 +35,8 @@ void DLT_Log::clear(void)
{ {
DLT_Type::DLT_Msg_Node *p_target = this->Msg_List_Head; DLT_Type::DLT_Msg_Node *p_target = this->Msg_List_Head;
this->Msg_List_Head = this->Msg_List_Head->p_next; this->Msg_List_Head = this->Msg_List_Head->p_next;
free(p_target->Msg.payload_buffer); if (p_target->Msg.payload_buffer != nullptr)
free(p_target->Msg.payload_buffer);
free(p_target); free(p_target);
} }
@ -191,6 +192,12 @@ DLT_Type::DLT_Err DLT_Log::dlt_file_read_payload(FILE *p_file, DLT_Type::DLT_Msg
if (Msg == nullptr) if (Msg == nullptr)
return DLT_Type::DLT_ERROR_NULL_POINTER; return DLT_Type::DLT_ERROR_NULL_POINTER;
if (Msg->payload_length == 0)
{
Msg->payload_buffer = nullptr;
return DLT_Type::DLT_ERROR_NONE;
}
// 读取Payload // 读取Payload
Msg->payload_buffer = (uint8_t *)malloc(Msg->payload_length); Msg->payload_buffer = (uint8_t *)malloc(Msg->payload_length);
this->mem_use += Msg->payload_length; this->mem_use += Msg->payload_length;
@ -225,7 +232,7 @@ DLT_Type::DLT_Err DLT_Log::load_from_file(const char *file_name_str)
DLT_Type::DLT_Err err = DLT_Type::DLT_ERROR_NONE; DLT_Type::DLT_Err err = DLT_Type::DLT_ERROR_NONE;
while (1) while (1)
{ {
DLT_Type::DLT_Msg Msg; DLT_Type::DLT_Msg Msg = {0};
err = dlt_file_read_header(p_file, &Msg); err = dlt_file_read_header(p_file, &Msg);
if (err != DLT_Type::DLT_ERROR_NONE) if (err != DLT_Type::DLT_ERROR_NONE)