Skip to contentSkip to conversation

sparc: piggyback: handle invalid image

PATCH Applied Corentin Labbe 2 participants 2 messages Jun 10, 2020 – Jun 22, 2020 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sparc: piggyback: handle invalid image

With an old elftoaout, the generation of tftpboot.img fail with "lseek:
invalid argument".
This is due to offset being negative.

Instead of printing this error message, let's print a better one.

---
 arch/sparc/boot/piggyback.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/sparc/boot/piggyback.c +4 -0
index a7a38fb4ece0..613e23a1016e 100644
@@ -154,6 +154,10 @@ static off_t get_hdrs_offset(int kernelfd, const char *filename)
 		offset -= LOOKBACK;
 		/* skip a.out header */
 		offset += AOUT_TEXT_OFFSET;
+		if (offset < 0) {
+			errno = -EINVAL;
+			die("Calculated a negative offset, probably elftoaout generated an invalid image. Did you use a recent elftoaout ?");
+		}
 		if (lseek(kernelfd, offset, SEEK_SET) < 0)
 			die("lseek");
 		if (read(kernelfd, buffer, BUFSIZE) != BUFSIZE)
Signature · 1 line
2.26.2
maintainer Applied
#1 lore raw

From: Corentin Labbe <[email protected]>
Date: Wed, 10 Jun 2020 07:55:19 +0000

Quoted 7 lines

With an old elftoaout, the generation of tftpboot.img fail with "lseek:
invalid argument".
This is due to offset being negative.

Instead of printing this error message, let's print a better one.

Applied, thank you.