[PATCH] uclinux: delay binfmt_flat trace

Modify the initial trace output (which is based on flags in the binary
header) so that it is not done until after the magic number check. This
may well not be a flat format binary, so the flags could be invalid.
(Prime example, running a script).

Changes prompted by patches from Stuart Hughs.

Signed-off-by: Greg Ungerer <gerg@uclinux.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Greg Ungerer and committed by
Linus Torvalds
845884d3 082f2c1c

+10 -7
+10 -7
fs/binfmt_flat.c
··· 442 flags = ntohl(hdr->flags); 443 rev = ntohl(hdr->rev); 444 445 - if (flags & FLAT_FLAG_KTRACE) 446 - printk("BINFMT_FLAT: Loading file: %s\n", bprm->filename); 447 - 448 - if (strncmp(hdr->magic, "bFLT", 4) || 449 - (rev != FLAT_VERSION && rev != OLD_FLAT_VERSION)) { 450 /* 451 * because a lot of people do not manage to produce good 452 * flat binaries, we leave this printk to help them realise 453 * the problem. We only print the error if its not a script file 454 */ 455 if (strncmp(hdr->magic, "#!", 2)) 456 - printk("BINFMT_FLAT: bad magic/rev (0x%x, need 0x%x)\n", 457 - rev, (int) FLAT_VERSION); 458 return -ENOEXEC; 459 } 460
··· 442 flags = ntohl(hdr->flags); 443 rev = ntohl(hdr->rev); 444 445 + if (strncmp(hdr->magic, "bFLT", 4)) { 446 /* 447 * because a lot of people do not manage to produce good 448 * flat binaries, we leave this printk to help them realise 449 * the problem. We only print the error if its not a script file 450 */ 451 if (strncmp(hdr->magic, "#!", 2)) 452 + printk("BINFMT_FLAT: bad header magic\n"); 453 + return -ENOEXEC; 454 + } 455 + 456 + if (flags & FLAT_FLAG_KTRACE) 457 + printk("BINFMT_FLAT: Loading file: %s\n", bprm->filename); 458 + 459 + if (rev != FLAT_VERSION && rev != OLD_FLAT_VERSION) { 460 + printk("BINFMT_FLAT: bad flat file version 0x%x (supported 0x%x and 0x%x)\n", rev, FLAT_VERSION, OLD_FLAT_VERSION); 461 return -ENOEXEC; 462 } 463