diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2005-12-08 22:34:01 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2005-12-08 22:34:01 +0000 |
commit | 3187ac6a85e69675328b9b7388db9e00fe6aa434 (patch) | |
tree | 7460202ed8545396d15d4a421b24b3a59ec64da7 /usr.bin/gprof/gprof.c | |
parent | 587ea03acd07cf2f51416ddcbbeb833de7dd8d94 (diff) |
Check fread() return value to get sane error message for too-small
gmon header. Idea from Alexey Dobriyan
Diffstat (limited to 'usr.bin/gprof/gprof.c')
-rw-r--r-- | usr.bin/gprof/gprof.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/usr.bin/gprof/gprof.c b/usr.bin/gprof/gprof.c index 1aefa537dc5..19f5cde1c63 100644 --- a/usr.bin/gprof/gprof.c +++ b/usr.bin/gprof/gprof.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gprof.c,v 1.15 2005/05/03 08:09:52 art Exp $ */ +/* $OpenBSD: gprof.c,v 1.16 2005/12/08 22:34:00 millert Exp $ */ /* $NetBSD: gprof.c,v 1.8 1995/04/19 07:15:59 cgd Exp $ */ /* @@ -40,7 +40,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)gprof.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: gprof.c,v 1.15 2005/05/03 08:09:52 art Exp $"; +static char rcsid[] = "$OpenBSD: gprof.c,v 1.16 2005/12/08 22:34:00 millert Exp $"; #endif #endif /* not lint */ @@ -250,7 +250,8 @@ openpfile(char *filename) if((pfile = fopen(filename, "r")) == NULL) err(1, "fopen: %s", filename); - fread(&tmp, sizeof(struct gmonhdr), 1, pfile); + if (fread(&tmp, sizeof(struct gmonhdr), 1, pfile) != 1) + errx(1, "%s: bad gmon header", filename); if ( s_highpc != 0 && ( tmp.lpc != gmonhdr.lpc || tmp.hpc != gmonhdr.hpc || tmp.ncnt != gmonhdr.ncnt)) errx(1, "%s: incompatible with first gmon file", filename); |