diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2004-04-29 13:34:38 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2004-04-29 13:34:38 +0000 |
commit | 783f8daf3c5edc6b1f360959dec504e9ff7eab8f (patch) | |
tree | c7b495dab2ad21baee90daa23cbd842505f22b86 /usr.bin/nm/nm.c | |
parent | 05a0facf53ef4a4e9f9659889e311c8ea55c54ee (diff) |
Correctly report empty a.out objects as "no name list" instead of "bad format".
ok mickey@ millert@
Diffstat (limited to 'usr.bin/nm/nm.c')
-rw-r--r-- | usr.bin/nm/nm.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/usr.bin/nm/nm.c b/usr.bin/nm/nm.c index f934c413a15..ff4ebb74211 100644 --- a/usr.bin/nm/nm.c +++ b/usr.bin/nm/nm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nm.c,v 1.23 2004/01/14 04:23:26 millert Exp $ */ +/* $OpenBSD: nm.c,v 1.24 2004/04/29 13:34:37 miod Exp $ */ /* $NetBSD: nm.c,v 1.7 1996/01/14 23:04:03 pk Exp $ */ /* @@ -42,7 +42,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)nm.c 8.1 (Berkeley) 6/6/93"; #endif -static const char rcsid[] = "$OpenBSD: nm.c,v 1.23 2004/01/14 04:23:26 millert Exp $"; +static const char rcsid[] = "$OpenBSD: nm.c,v 1.24 2004/04/29 13:34:37 miod Exp $"; #include <sys/param.h> #include <sys/mman.h> @@ -247,6 +247,7 @@ process_file(int count, const char *fname) union hdr exec_head; FILE *fp; int retval; + size_t bytes; char magic[SARMAG]; if (!(fp = fopen(fname, "r"))) { @@ -261,10 +262,14 @@ process_file(int count, const char *fname) * first check whether this is an object file - read a object * header, and skip back to the beginning */ - if (fread((char *)&exec_head, sizeof(exec_head), (size_t)1, fp) != 1) { - warnx("%s: bad format", fname); - (void)fclose(fp); - return(1); + bzero(&exec_head, sizeof(exec_head)); + bytes = fread((char *)&exec_head, 1, sizeof(exec_head), fp); + if (bytes < sizeof(exec_head)) { + if (bytes < sizeof(exec_head.aout) || IS_ELF(exec_head.elf)) { + warnx("%s: bad format", fname); + (void)fclose(fp); + return(1); + } } rewind(fp); |