Skip to content

Dangling plugin data entry leaves MeshtasticData pointer after free #4

Description

@the-Drunken-coder

Issue:

In src/plugins/meshtastic.c:73-89 (see cleanup routine meshtastic_cleanup), the plugin frees the MeshtasticData struct during cleanup, but never removes the corresponding entry from context->plugins_data:

static void meshtastic_cleanup(DeadlightContext *context) {
    MeshtasticData *data = g_hash_table_lookup(context->plugins_data, "meshtastic");
    if (!data) return;
    // ... free fields ...
    g_free(data);
}

If the plugin is ever reloaded or another lookup occurs, context->plugins_data still contains a dangling pointer, leading to unsafe use or double-free. Compare to most plugin management patterns, where plugin hash entries are always removed on unload/unregister.

Key code:

// src/plugins/meshtastic.c
static void meshtastic_cleanup(DeadlightContext *context) {
    MeshtasticData *data = g_hash_table_lookup(context->plugins_data, "meshtastic");
    if (!data) return;
    ...
    g_free(data);
    // Missing: g_hash_table_remove(context->plugins_data, "meshtastic");
}

Impact:

  • Dangling pointer in context leads to UAF, double free, crash, or plugin restart bugs.
  • Leaks plugin hash entry after free.

Suggested fix:
Remove the plugin data entry from context->plugins_data during cleanup:

g_hash_table_remove(context->plugins_data, "meshtastic");

This must be added before freeing the MeshtasticData struct.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions