Avoid using uninitialized memory in split go

Since boot_read_image_headers only failed when reading headers from
both Slots failed, it could happen that even with a failure reading
Slot 1, this data would still be used by split booting. Now when
reading image headers an extra parameter allows the caller to ask
for failure when any slot read failed.

JIRA: MCUB-56
Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/boot/bootutil/src/loader.c b/boot/bootutil/src/loader.c
index 75494f6..ab8ac7b 100644
--- a/boot/bootutil/src/loader.c
+++ b/boot/bootutil/src/loader.c
@@ -285,7 +285,7 @@
 }
 
 static int
-boot_read_image_headers(void)
+boot_read_image_headers(bool require_all)
 {
     int rc;
     int i;
@@ -293,11 +293,13 @@
     for (i = 0; i < BOOT_NUM_SLOTS; i++) {
         rc = boot_read_image_header(i, boot_img_hdr(&boot_data, i));
         if (rc != 0) {
-            /* If at least the first slot's header was read successfully, then
-             * the boot loader can attempt a boot.  Failure to read any headers
-             * is a fatal error.
+            /* If `require_all` is set, fail on any single fail, otherwise
+             * if at least the first slot's header was read successfully,
+             * then the boot loader can attempt a boot.
+             *
+             * Failure to read any headers is a fatal error.
              */
-            if (i > 0) {
+            if (i > 0 && !require_all) {
                 return 0;
             } else {
                 return rc;
@@ -1338,7 +1340,7 @@
     }
 
     /* Attempt to read an image header from each slot. */
-    rc = boot_read_image_headers();
+    rc = boot_read_image_headers(false);
     if (rc != 0) {
         goto out;
     }
@@ -1409,7 +1411,7 @@
     }
 
     if (reload_headers) {
-        rc = boot_read_image_headers();
+        rc = boot_read_image_headers(false);
         if (rc != 0) {
             goto out;
         }
@@ -1485,7 +1487,7 @@
         goto done;
     }
 
-    rc = boot_read_image_headers();
+    rc = boot_read_image_headers(true);
     if (rc != 0) {
         goto done;
     }