Module Name:    src
Committed By:   riastradh
Date:           Sun Oct 27 12:12:39 UTC 2024

Modified Files:
        src/sys/dev/acpi: apei_hest.c

Log Message:
apei(4): Paranoia: Clamp multiplication to SIZE_MAX too.

This makes it clear that the result is guaranteed not to overflow
size_t.  Previously it was only implied because on all NetBSD ports,
SIZE_MAX > INT32_MAX, but let's make it clearer instead of relying on
tacitly on that assumption.

No functional change intended.

Noticed while preparing for:

PR kern/58775: apei(4) spamming console


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/acpi/apei_hest.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/apei_hest.c
diff -u src/sys/dev/acpi/apei_hest.c:1.3 src/sys/dev/acpi/apei_hest.c:1.4
--- src/sys/dev/acpi/apei_hest.c:1.3	Thu Mar 21 02:35:09 2024
+++ src/sys/dev/acpi/apei_hest.c	Sun Oct 27 12:12:39 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: apei_hest.c,v 1.3 2024/03/21 02:35:09 riastradh Exp $	*/
+/*	$NetBSD: apei_hest.c,v 1.4 2024/10/27 12:12:39 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -52,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: apei_hest.c,v 1.3 2024/03/21 02:35:09 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apei_hest.c,v 1.4 2024/10/27 12:12:39 riastradh Exp $");
 
 #include <sys/types.h>
 
@@ -907,7 +907,7 @@ apei_hest_attach(struct apei_softc *sc)
 	 * limit on it; if you have gigabytes of HEST something is
 	 * probably wrong.
 	 */
-	if (n > INT32_MAX/sizeof(hsc->hsc_source[0])) {
+	if (n > MIN(SIZE_MAX, INT32_MAX)/sizeof(hsc->hsc_source[0])) {
 		aprint_error_dev(sc->sc_dev, "HEST: too many error sources\n");
 		return;
 	}

Reply via email to