Skip to content

Dangling pointer "dev_handle" in hal_esp32_i2c.c #425

Description

@n-PPV

Issue

In hal_esp32_i2c.c (i2c_master driver, ESP-IDF ≥ 5.2) functions hal_i2c_send() and hal_i2c_receive() use i2c_master_bus_rm_device() but they do not assign NULL to the pointer pointing the freed memory, leaving it dangling (lines 252, 319). At the same time, hal_i2c_release() checks for non-NULL value of hal->dev_handle before calling i2c_master_bus_rm_device, leading to double free (line 342).

Observed Imact

While working with ESP32-C6 the bug lead to heap poisoning.

Suggested fix

My suggestion is to add a NULL assignment to each pointer given as argument to i2c_master_bus_rm_device() just after calling the function (function called in lines 252, 319, 343). Will follow up with a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions