]> git.ipfire.org Git - people/ms/dnsmasq.git/commitdiff
isc.c: Improve OOM handling when reading DHCP leases dhcp-lease
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 4 Feb 2016 23:45:09 +0000 (23:45 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 4 Feb 2016 23:45:09 +0000 (23:45 +0000)
This patch mainly suppresses a compiler warning. The application
will still crash.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/isc.c

index 51064426f17fd3b6153e6e71b3d3726825e0785e..a0e415b6084dfabe4b3fb3ce81a828313ecf6866 100644 (file)
--- a/src/isc.c
+++ b/src/isc.c
   Michael Tremer.
 */
 
+#define _GNU_SOURCE
+
+#include <assert.h>
+#include <stdio.h>
+
 #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;