fix broken overflow test.

This commit is contained in:
christos 2009-04-26 15:55:50 +00:00
parent 067a8b527b
commit c37383f14b
1 changed files with 10 additions and 6 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: look.c,v 1.13 2009/04/12 14:01:20 lukem Exp $ */ /* $NetBSD: look.c,v 1.14 2009/04/26 15:55:50 christos Exp $ */
/*- /*-
* Copyright (c) 1991, 1993 * Copyright (c) 1991, 1993
@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 1993\
#if 0 #if 0
static char sccsid[] = "@(#)look.c 8.2 (Berkeley) 5/4/95"; static char sccsid[] = "@(#)look.c 8.2 (Berkeley) 5/4/95";
#endif #endif
__RCSID("$NetBSD: look.c,v 1.13 2009/04/12 14:01:20 lukem Exp $"); __RCSID("$NetBSD: look.c,v 1.14 2009/04/26 15:55:50 christos Exp $");
#endif /* not lint */ #endif /* not lint */
/* /*
@ -103,6 +103,7 @@ main(argc, argv)
int ch, fd, termchar; int ch, fd, termchar;
char *back, *front, *string, *p; char *back, *front, *string, *p;
const char *file; const char *file;
size_t len;
string = NULL; string = NULL;
file = _PATH_WORDS; file = _PATH_WORDS;
@ -143,12 +144,15 @@ main(argc, argv)
if ((fd = open(file, O_RDONLY, 0)) < 0 || fstat(fd, &sb)) if ((fd = open(file, O_RDONLY, 0)) < 0 || fstat(fd, &sb))
err(2, "%s", file); err(2, "%s", file);
if (sb.st_size > (off_t)SIZE_T_MAX) len = (size_t)sb.st_size;
err(2, "%s: %s", file, strerror(EFBIG)); if ((off_t)len != sb.st_size) {
if ((front = mmap(NULL, (size_t)sb.st_size, errno = EFBIG;
err(2, "%s", file);
}
if ((front = mmap(NULL, len,
PROT_READ, MAP_FILE|MAP_SHARED, fd, (off_t)0)) == NULL) PROT_READ, MAP_FILE|MAP_SHARED, fd, (off_t)0)) == NULL)
err(2, "%s", file); err(2, "%s", file);
back = front + sb.st_size; back = front + len;
exit(look(string, front, back)); exit(look(string, front, back));
} }