From f83807647e171def9244a7f1d8d9af8e8e79f847 Mon Sep 17 00:00:00 2001 From: Mikhail Dmitrichenko Date: Wed, 17 Dec 2025 11:52:16 +0300 Subject: [PATCH] os: avoid closing null fd at Fopen In `Fopen` function variable `iop` may store NULL as a result of `fopen` call. In this case, if later privileges couldn't be restored (`seteuid` call fails), further `fclose(iop)` call will cause runtime error. This commit adds check `iop` for NULL before calling `fclose` to prevent potential NULL pointer dereference. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Mikhail Dmitrichenko Part-of: --- os/utils.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/os/utils.c b/os/utils.c index 57c21a448..8963b53a0 100644 --- a/os/utils.c +++ b/os/utils.c @@ -1215,7 +1215,9 @@ Fopen(const char *file, const char *type) iop = fopen(file, type); if (seteuid(euid) == -1) { - fclose(iop); + if (iop) { + fclose(iop); + } return NULL; } return iop;