DragonFlyBSD Kernel Audit
DF-2826 / fix.diff
← back to finding ↓ download raw
--- a/sys/kern/kern_checkpoint.c	2026-09-01 19:51:22.715034584 +0000
+++ b/sys/kern/kern_checkpoint.c	2026-09-01 19:51:22.731034381 +0000
@@ -230,6 +230,10 @@
 	if ((error = elf_gethdr(fp, ehdr)) != 0)
 		goto done;
 	nbyte = sizeof(Elf_Phdr) * ehdr->e_phnum;
+	if (ehdr->e_phnum == 0) {
+		error = EINVAL;
+		goto done;
+	}
 	phdr = kmalloc(nbyte, M_TEMP, M_WAITOK);
 
 	/* fetch description of program writable mappings */
@@ -664,7 +668,9 @@
 		if (fdalloc(lp->lwp_proc, cfi->cfi_index, &fd) != 0) {
 			PRINTF(("can't currently restore fd: %d\n",
 			       cfi->cfi_index));
-			fp_close(fp);
+			error = EBADF;
+			if (tempfp)
+				fp_close(tempfp);
 			goto done;
 		}
 		KKASSERT(fd == cfi->cfi_index);