Skip to contentSkip to conversation

legacycfg.c: avoid closing file twice

PATCH In review Leo Sandoval 2 participants 2 messages Oct 16, 2024 – Oct 24, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 legacycfg.c: avoid closing file twice

An Internal (at Red Hat) static soure code scan detected the issue below, pointing to an use-after-free scenario so remove the extra file close call.

    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);
---
 grub-core/commands/legacycfg.c | 1 -
 1 file changed, 1 deletion(-)
grub-core/commands/legacycfg.c +0 -1
index e9e9d94ef..3bf9fe2e4 100644
@@ -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;
Signature · 7 lines
2.46.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Leo Sandoval

An Internal (at Red Hat) static soure code scan detected the issue below, pointing to an use-after-free scenario so remove the extra file close call.

    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);
Quoted 1 line

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel