free() with nullptr is OK, but not if the size is unitialized, and the
authorderaadt <deraadt@openbsd.org>
Sat, 27 Nov 2021 06:14:10 +0000 (06:14 +0000)
committerderaadt <deraadt@openbsd.org>
Sat, 27 Nov 2021 06:14:10 +0000 (06:14 +0000)
fail label is reachable before the sizes are known.

sys/arch/powerpc64/dev/kexec.c

index 8673cad..bb106c7 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kexec.c,v 1.5 2020/09/02 16:07:31 deraadt Exp $       */
+/*     $OpenBSD: kexec.c,v 1.6 2021/11/27 06:14:10 deraadt Exp $       */
 
 /*
  * Copyright (c) 2019-2020 Visa Hankala
@@ -242,8 +242,10 @@ fail:
                km_free(symaddr, symsize, &kv_any, &kp_kexec);
        if (addr)
                km_free(addr, size, &kv_any, &kp_kexec);
-       free(sh, M_TEMP, shsize);
-       free(ph, M_TEMP, phsize);
+       if (sh)
+               free(sh, M_TEMP, shsize);
+       if (ph)
+               free(ph, M_TEMP, phsize);
        return error;
 }