From: Michael Tremer Date: Thu, 4 Feb 2016 23:45:09 +0000 (+0000) Subject: isc.c: Improve OOM handling when reading DHCP leases X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fheads%2Fdhcp-lease;p=people%2Fms%2Fdnsmasq.git isc.c: Improve OOM handling when reading DHCP leases This patch mainly suppresses a compiler warning. The application will still crash. Signed-off-by: Michael Tremer --- diff --git a/src/isc.c b/src/isc.c index 5106442..a0e415b 100644 --- a/src/isc.c +++ b/src/isc.c @@ -19,6 +19,11 @@ Michael Tremer. */ +#define _GNU_SOURCE + +#include +#include + #include "dnsmasq.h" #ifdef HAVE_ISC_READER @@ -34,10 +39,18 @@ struct isc_dhcp_lease { static struct isc_dhcp_lease* dhcp_lease_new(const char* hostname) { struct isc_dhcp_lease* lease = whine_malloc(sizeof(*lease)); + if (!lease) + return NULL; lease->name = strdup(hostname); if (daemon->domain_suffix) { - asprintf(&lease->fqdn, "%s.%s", hostname, daemon->domain_suffix); + int r = asprintf(&lease->fqdn, "%s.%s", hostname, daemon->domain_suffix); + + // Handle OOM + if (r < 0) { + free(lease); + return NULL; + } } lease->expires = 0; lease->next = NULL; @@ -210,6 +223,7 @@ void load_dhcp(time_t now) { // and append it to the list. if (!lease) { lease = dhcp_lease_new(hostname); + assert(lease); lease->next = leases; leases = lease;