]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh-network: Avoid possible NULL deref in cmdNetworkDHCPLeases
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 8 Jun 2016 09:32:09 +0000 (11:32 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 8 Jun 2016 13:56:08 +0000 (15:56 +0200)
Problem is, localtime_r() returns a pointer to converted time or
NULL in case of an error. But checking the glibc sources, error
will occur iff a NULL has been passed as an either of arguments
the function takes. But GCC fails to see that:

../../tools/virsh-network.c: In function 'cmdNetworkDHCPLeases':
../../tools/virsh-network.c:1370:12: error: potential null pointer dereference [-Werror=null-dereference]
         ts = *localtime_r(&expirytime_tmp, &ts);
         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
tools/virsh-network.c

index 22ea016f40757797eb1399dc967dfa343989eb4e..5abcda37cde24e9a5040a8ebef4079db6efcfa6f 100644 (file)
@@ -1367,7 +1367,7 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd)
         time_t expirytime_tmp = lease->expirytime;
         struct tm ts;
         char expirytime[32];
-        ts = *localtime_r(&expirytime_tmp, &ts);
+        localtime_r(&expirytime_tmp, &ts);
         strftime(expirytime, sizeof(expirytime), "%Y-%m-%d %H:%M:%S", &ts);
 
         if (lease->type == VIR_IP_ADDR_TYPE_IPV4)