x1000: don't close fd 0 when a bootloader backup fails early

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]>
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit fae5c8d0676ae785810e734184cbf52944b133b1
Author: Michael McAllister <[email protected]>
Date:   Sun Aug 9 23:21:34 2026 +0100

    x1000: don't close fd 0 when a bootloader backup fails early
    
    backup_bootloader() and restore_bootloader() initialise `fd = 0` and their error paths close it unconditionally. Any failure before the file is opened updater_init(), or the size check between them therefore reaches close(0) and closes whatever fd 0 happens to be. On a native target that is whatever the filesystem layer handed out first, so an unrelated open file is closed and the damage surfaces somewhere else entirely.
    
    Initialise to -1 instead, which is the value close() ignores.
    
    Found by inspection while bringing up another Ingenic target. Not run on
    X1000 hardware.
    
    Change-Id: Ib043f79f0b7edc7c70ccd77cbff54e264ed2b2de
    Co-Authored-By: Claude Opus 4.8

diff --git a/firmware/target/mips/ingenic_x1000/installer-x1000.c b/firmware/target/mips/ingenic_x1000/installer-x1000.c
index 769371d29d..70ed270408 100644
--- a/firmware/target/mips/ingenic_x1000/installer-x1000.c
+++ b/firmware/target/mips/ingenic_x1000/installer-x1000.c
@@ -237,7 +237,7 @@ int install_bootloader(const char* filename)
 
 int backup_bootloader(const char* filename)
 {
-    int rc, fd = 0;
+    int rc, fd = -1;
     struct updater u;
 
     rc = updater_init(&u);
@@ -281,7 +281,7 @@ int backup_bootloader(const char* filename)
 
 int restore_bootloader(const char* filename)
 {
-    int rc, fd = 0;
+    int rc, fd = -1;
     struct updater u;
 
     rc = updater_init(&u);
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.