summaryrefslogtreecommitdiff
path: root/usr.bin/file/apprentice.c
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@cvs.openbsd.org>2014-01-16 21:45:34 +0000
committerTobias Stoeckmann <tobias@cvs.openbsd.org>2014-01-16 21:45:34 +0000
commit58cb7c8411f77d62742b747a0d90cc4ba0936630 (patch)
treeb1b25541b3c8fdc01cd86dfa0b01099930353f33 /usr.bin/file/apprentice.c
parent6ed9aa2cf5ac1cabb397f2b5bbba349072644e86 (diff)
Avoid size_t overflow in apprentice_map.
ok millert
Diffstat (limited to 'usr.bin/file/apprentice.c')
-rw-r--r--usr.bin/file/apprentice.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/usr.bin/file/apprentice.c b/usr.bin/file/apprentice.c
index 42d8ca2514d..90ba8398693 100644
--- a/usr.bin/file/apprentice.c
+++ b/usr.bin/file/apprentice.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: apprentice.c,v 1.29 2009/11/11 16:21:51 jsg Exp $ */
+/* $OpenBSD: apprentice.c,v 1.30 2014/01/16 21:45:33 tobias Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
@@ -41,6 +41,7 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+#include <limits.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
@@ -1897,8 +1898,9 @@ apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
file_error(ms, errno, "cannot stat `%s'", dbname);
goto error1;
}
- if (st.st_size < 8) {
- file_error(ms, 0, "file `%s' is too small", dbname);
+ if (st.st_size < 8 || st.st_size > SIZE_MAX) {
+ file_error(ms, 0, "file `%s' is too %s", dbname,
+ st.st_size > SIZE_MAX ? "large" : "small");
goto error1;
}