From ea86b9e64b811753d9eabe0f560ee189fbe5d0c1 Mon Sep 17 00:00:00 2001
From: Kumar Gala <galak@kernel.crashing.org>
Date: Fri, 29 Aug 2008 19:08:29 -0500
Subject: [PATCH] Prevent crash if random/invalid ramdisks are passed to bootm

Adds returning an error from the ramdisk detection code if
its not a real ramdisk (invalid).  There is no reason we can't
just return back to the console if we detect an invalid
ramdisk or CRC error.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
---
 common/cmd_bootm.c | 2 +-
 common/image.c     | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index 374085ca38..751f5b99d4 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -246,7 +246,7 @@ static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 		ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
 				&images.rd_start, &images.rd_end);
 		if (ret) {
-			puts ("Ramdisk image is corrupt\n");
+			puts ("Ramdisk image is corrupt or invalid\n");
 			return 1;
 		}
 
diff --git a/common/image.c b/common/image.c
index 0acdcf132a..94f01ad455 100644
--- a/common/image.c
+++ b/common/image.c
@@ -749,7 +749,7 @@ int genimg_has_config (bootm_headers_t *images)
  *     rd_start and rd_end are set to ramdisk start/end addresses if
  *     ramdisk image is found and valid
  *
- *     1, if ramdisk image is found but corrupted
+ *     1, if ramdisk image is found but corrupted, or invalid
  *     rd_start and rd_end are set to 0 if no ramdisk exists
  */
 int boot_get_ramdisk (int argc, char *argv[], bootm_headers_t *images,
@@ -936,6 +936,7 @@ int boot_get_ramdisk (int argc, char *argv[], bootm_headers_t *images,
 		default:
 			puts ("Wrong Ramdisk Image Format\n");
 			rd_data = rd_len = rd_load = 0;
+			return 1;
 		}
 
 #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO)
-- 
2.39.5