From: Leo Sandoval Date: Wed, 16 Oct 2024 17:54:38 +0000 (-0600) Subject: commands/legacycfg: Avoid closing file twice X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f26b39860d32e2b9edb30370349e40b1ac7055c8;p=thirdparty%2Fgrub.git commands/legacycfg: Avoid closing file twice An internal (at Red Hat) static soure code scan detected an use-after-free scenario: Error: USE_AFTER_FREE (CWE-416): grub-2.06/grub-core/commands/legacycfg.c:194: freed_arg: "grub_file_close" frees "file". grub-2.06/grub-core/commands/legacycfg.c:201: deref_arg: Calling "grub_file_close" dereferences freed pointer "file". # 199| if (!args) # 200| { # 201|-> grub_file_close (file); # 202| grub_free (suffix); # 203| grub_free (entrysrc); So, remove the extra file close call. Signed-off-by: Leo Sandoval Reviewed-by: Daniel Kiper --- diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c index e9e9d94ef..3bf9fe2e4 100644 --- a/grub-core/commands/legacycfg.c +++ b/grub-core/commands/legacycfg.c @@ -198,7 +198,6 @@ legacy_file (const char *filename) const char **args = grub_malloc (sizeof (args[0])); if (!args) { - grub_file_close (file); grub_free (suffix); grub_free (entrysrc); return grub_errno;