From 3187ac6a85e69675328b9b7388db9e00fe6aa434 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Thu, 8 Dec 2005 22:34:01 +0000 Subject: Check fread() return value to get sane error message for too-small gmon header. Idea from Alexey Dobriyan --- usr.bin/gprof/gprof.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'usr.bin/gprof/gprof.c') 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); -- cgit v1.2.3