From c6aa336a271da54d44ba55fd21c2966d6197e2c3 Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Thu, 6 Mar 2014 16:50:55 +0000 Subject: [PATCH] don't compare SIZE_MAX to off_t; if they are the same size in bytes it is wrong. Use a more appropriate comparison. --- src/apprentice.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/apprentice.c b/src/apprentice.c index e1869b23..5eadbe05 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: apprentice.c,v 1.197 2014/03/06 16:16:56 christos Exp $") +FILE_RCSID("@(#)$File: apprentice.c,v 1.198 2014/03/06 16:18:53 christos Exp $") #endif /* lint */ #include "magic.h" @@ -52,8 +52,10 @@ FILE_RCSID("@(#)$File: apprentice.c,v 1.197 2014/03/06 16:16:56 christos Exp $") #include #endif -#ifndef SIZE_MAX -#define SIZE_MAX ((size_t)~0) +#ifndef SSIZE_MAX +#define MAXMAGIC_SIZE ((ssize_t)0x7fffffff) +#else +#define MAXMAGIC_SIZE SSIZE_MAX #endif #define EATAB {while (isascii((unsigned char) *l) && \ @@ -2608,7 +2610,7 @@ apprentice_map(struct magic_set *ms, const char *fn) file_error(ms, errno, "cannot stat `%s'", dbname); goto error; } - if (st.st_size < 8 || st.st_size > (off_t)SIZE_MAX) { + if (st.st_size < 8 || st.st_size > MAXMAGIC_SIZE) { file_error(ms, 0, "file `%s' is too %s", dbname, st.st_size < 8 ? "small" : "large"); goto error; -- 2.40.0