From 8b3ef2c346db74d720e6701598c0b3e01404a73e Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Wed, 29 Apr 2026 18:27:44 +0700 Subject: [PATCH] defensive: NULL-check calloc results before dereferencing Five sites allocated with calloc() and dereferenced the result on the very next line. Under OOM the module would have segfaulted instead of degrading. Each site now bails (or sends a Canceled D-Bus error, in the agent path) when the allocation fails. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/e_mod_popup.c | 1 + src/iwd/iwd_agent.c | 3 +++ src/iwd/iwd_manager.c | 1 + src/ui/wifi_auth.c | 1 + src/ui/wifi_hidden.c | 1 + 5 files changed, 7 insertions(+) diff --git a/src/e_mod_popup.c b/src/e_mod_popup.c index 54f40ae..c8ef68a 100644 --- a/src/e_mod_popup.c +++ b/src/e_mod_popup.c @@ -523,6 +523,7 @@ e_iwd_popup_toggle(E_Gadcon_Client *gcc) if (!gcc || !e_iwd) return; Popup *p = calloc(1, sizeof(*p)); + if (!p) return; _popup = p; p->gp = e_gadcon_popup_new(gcc, EINA_FALSE); diff --git a/src/iwd/iwd_agent.c b/src/iwd/iwd_agent.c index df8a5b4..e378039 100644 --- a/src/iwd/iwd_agent.c +++ b/src/iwd/iwd_agent.c @@ -73,6 +73,9 @@ _request_passphrase_cb(const Eldbus_Service_Interface *iface EINA_UNUSED, "No UI handler"); Iwd_Agent_Request *req = calloc(1, sizeof(*req)); + if (!req) + return eldbus_message_error_new(msg, "net.connman.iwd.Agent.Error.Canceled", + "Out of memory"); req->agent = _self; req->msg = eldbus_message_ref((Eldbus_Message *)msg); _self->cb(_self->data, req, path); diff --git a/src/iwd/iwd_manager.c b/src/iwd/iwd_manager.c index 941e907..ec4648e 100644 --- a/src/iwd/iwd_manager.c +++ b/src/iwd/iwd_manager.c @@ -63,6 +63,7 @@ iwd_manager_listener_add(Iwd_Manager *m, Iwd_Manager_Cb cb, void *data) { if (!m || !cb) return; Listener *l = calloc(1, sizeof(*l)); + if (!l) return; l->cb = cb; l->data = data; m->listeners = eina_list_append(m->listeners, l); } diff --git a/src/ui/wifi_auth.c b/src/ui/wifi_auth.c index 24d21d3..81bcfce 100644 --- a/src/ui/wifi_auth.c +++ b/src/ui/wifi_auth.c @@ -68,6 +68,7 @@ wifi_auth_prompt(Evas_Object *parent EINA_UNUSED, const char *ssid, Wifi_Auth_Cb cb, void *data) { Auth_Ctx *c = calloc(1, sizeof(*c)); + if (!c) return NULL; c->cb = cb; c->data = data; /* A floating top-level window so the popup is actually visible — diff --git a/src/ui/wifi_hidden.c b/src/ui/wifi_hidden.c index e6b9252..2f93215 100644 --- a/src/ui/wifi_hidden.c +++ b/src/ui/wifi_hidden.c @@ -104,6 +104,7 @@ void wifi_hidden_prompt(Evas_Object *parent EINA_UNUSED, Wifi_Hidden_Cb cb, void *data) { Hidden_Ctx *c = calloc(1, sizeof(*c)); + if (!c) { if (cb) cb(data, NULL, NULL, EINA_FALSE); return; } c->cb = cb; c->data = data; /* Floating top-level so the popup actually shows. */