From 9b2f2fbfcbc51f77e96a41e62b1c06a8ccd4ca15 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Wed, 23 Oct 2024 16:55:16 +0000 Subject: [PATCH] devmatch: Catch truncated linker hints files PR: 282268 Reviewed by: christos, imp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D47243 --- sbin/devmatch/devmatch.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sbin/devmatch/devmatch.c b/sbin/devmatch/devmatch.c index 49f9be00a2e7..4a5a300ca313 100644 --- a/sbin/devmatch/devmatch.c +++ b/sbin/devmatch/devmatch.c @@ -127,6 +127,12 @@ read_linker_hints(void) err(1, "Can't open %s for reading", fn); } + if (len < sizeof(int)) { + warnx("Linker hints file too short."); + free(hints); + hints = NULL; + return; + } if (*(int *)(intptr_t)hints != LINKER_HINTS_VERSION) { warnx("Linker hints version %d doesn't match expected %d.", *(int *)(intptr_t)hints, LINKER_HINTS_VERSION);