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) <noreply@anthropic.com>
This commit is contained in:
nemunaire 2026-04-29 18:27:44 +07:00
commit 8b3ef2c346
5 changed files with 7 additions and 0 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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);
}

View file

@ -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 —

View file

@ -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. */