Date: Fri, 24 Jan 2003 17:20:04 -0800 (PST) From: David Schultz <dschultz@uclink.Berkeley.EDU> To: freebsd-bugs@FreeBSD.org Subject: Re: i386/45391: /usr/bin/cmp coredumps while reading a faulty CD-R Message-ID: <200301250120.h0P1K4fg071431@freefall.freebsd.org>
index | next in thread | raw e-mail
The following reply was made to PR i386/45391; it has been noted by GNATS.
From: David Schultz <dschultz@uclink.Berkeley.EDU>
To: Cinek <cinekcvs@gmx.net>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: i386/45391: /usr/bin/cmp coredumps while reading a faulty CD-R
Date: Fri, 24 Jan 2003 17:17:13 -0800
> >Number: 45391
> >Category: i386
> >Synopsis: /usr/bin/cmp coredumps while reading a faulty CD-R
...
> >Description:
> When using the command /usr/bin/cmp from the default
> FreeBSD-4.7 package, it is possible to produce a coredump.
> It seems, there is a problem in handling errors while
> reading faulty files. It happened to me while I was comparing
> two files which I suspected to be dupes on my CD-Rs.
This is not the first time this buglet has confused someone, so
here's a simple fix. The diff is against -CURRENT, but it can be
applied to -STABLE as well.
Index: usr.bin/cmp/regular.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/cmp/regular.c,v
retrieving revision 1.17
diff -u -u -r1.17 regular.c
--- usr.bin/cmp/regular.c 2002/07/28 15:13:17 1.17
+++ usr.bin/cmp/regular.c 2003/01/25 01:14:02
@@ -45,7 +45,9 @@
#include <sys/stat.h>
#include <err.h>
+#include <errno.h>
#include <limits.h>
+#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -54,6 +56,7 @@
#include "extern.h"
static u_char *remmap(u_char *, int, off_t);
+static void segv_handler(int);
#define MMAP_CHUNK (8*1024*1024)
#define ROUNDPAGE(i) ((i) & ~pagemask)
@@ -67,6 +70,7 @@
int dfound;
off_t pagemask, off1, off2;
size_t pagesize;
+ struct sigaction act, oact;
if (skip1 > len1)
eofmsg(file1);
@@ -78,6 +82,12 @@
if (sflag && len1 != len2)
exit(DIFF_EXIT);
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = SA_NODEFER;
+ act.sa_handler = segv_handler;
+ if (sigaction(SIGSEGV, &act, &oact))
+ err(ERR_EXIT, "sigaction");
+
pagesize = getpagesize();
pagemask = (off_t)pagesize - 1;
off1 = ROUNDPAGE(skip1);
@@ -138,6 +148,9 @@
munmap(m1, MMAP_CHUNK);
munmap(m2, MMAP_CHUNK);
+ if (sigaction(SIGSEGV, &oact, NULL))
+ err(ERR_EXIT, "sigaction");
+
if (len1 != len2)
eofmsg (len1 > len2 ? file2 : file1);
if (dfound)
@@ -154,4 +167,10 @@
return (NULL);
madvise(mem, MMAP_CHUNK, MADV_SEQUENTIAL);
return (mem);
+}
+
+static void
+segv_handler(int sig) {
+
+ errc(ERR_EXIT, EIO, "(caught SIGSEGV)");
}
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200301250120.h0P1K4fg071431>
