init: Check chroot return value in sysupgrade_exec_upgraded()
authorFlorian Fainelli <f.fainelli@gmail.com>
Sat, 15 Jul 2017 17:51:20 +0000 (10:51 -0700)
committerFlorian Fainelli <f.fainelli@gmail.com>
Thu, 20 Jul 2017 15:30:06 +0000 (08:30 -0700)
chroot() can fail and its return value should be checked against, in that case
do an exit() since this is a fatal condition that we cannot recover from.

Fixes: 63789e51ed91 ("init: add support for sysupgrades triggered from preinit")
Reviewed-by: Matthias Schiffer <mschiffer@universe-factory.net>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
sysupgrade.c

index 30f1836135c9187be1fcb626a51e50faeadc514a..07e33f752d0c3be57962771cdf42f02576d42e7f 100644 (file)
@@ -26,8 +26,10 @@ void sysupgrade_exec_upgraded(const char *prefix, char *path, char *command)
 {
        char *wdt_fd = watchdog_fd();
        char *argv[] = { "/sbin/upgraded", NULL, NULL, NULL};
+       int ret;
 
-       if (chroot(prefix)) {
+       ret = chroot(prefix);
+       if (ret < 0) {
                fprintf(stderr, "Failed to chroot for upgraded exec.\n");
                return;
        }
@@ -45,5 +47,9 @@ void sysupgrade_exec_upgraded(const char *prefix, char *path, char *command)
        fprintf(stderr, "Failed to exec upgraded.\n");
        unsetenv("WDTFD");
        watchdog_set_cloexec(true);
-       chroot(".");
+       ret = chroot(".");
+       if (ret < 0) {
+               fprintf(stderr, "Failed to reset chroot, exiting.\n");
+               exit(EXIT_FAILURE);
+       }
 }