summaryrefslogtreecommitdiffstats
path: root/contrib/file/src
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2015-09-23 05:39:20 +0000
committerdelphij <delphij@FreeBSD.org>2015-09-23 05:39:20 +0000
commit34650d7da670a6653a5b0546b0656d1772779fd2 (patch)
tree51b0c2244d6415b10dbcb163aadb1f002f700e14 /contrib/file/src
parent3ef25e9daf8ff42f2a3c7781707a03823ff8eae6 (diff)
downloadFreeBSD-src-34650d7da670a6653a5b0546b0656d1772779fd2.zip
FreeBSD-src-34650d7da670a6653a5b0546b0656d1772779fd2.tar.gz
MFV r288140: update file to 5.25.
MFC after: 1 month
Diffstat (limited to 'contrib/file/src')
-rw-r--r--contrib/file/src/apprentice.c32
-rw-r--r--contrib/file/src/file.c4
-rw-r--r--contrib/file/src/file.h18
-rw-r--r--contrib/file/src/file_opts.h2
-rw-r--r--contrib/file/src/funcs.c60
-rw-r--r--contrib/file/src/gmtime_r.c6
-rw-r--r--contrib/file/src/localtime_r.c6
-rw-r--r--contrib/file/src/magic.c16
-rw-r--r--contrib/file/src/magic.h3
-rw-r--r--contrib/file/src/magic.h.in1
-rw-r--r--contrib/file/src/print.c10
-rw-r--r--contrib/file/src/readelf.c16
-rw-r--r--contrib/file/src/softmagic.c89
13 files changed, 154 insertions, 109 deletions
diff --git a/contrib/file/src/apprentice.c b/contrib/file/src/apprentice.c
index 607201c..66f64bd 100644
--- a/contrib/file/src/apprentice.c
+++ b/contrib/file/src/apprentice.c
@@ -32,7 +32,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.233 2015/06/10 00:57:41 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.238 2015/09/12 18:10:42 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -531,6 +531,7 @@ file_ms_alloc(int flags)
ms->elf_shnum_max = FILE_ELF_SHNUM_MAX;
ms->elf_phnum_max = FILE_ELF_PHNUM_MAX;
ms->elf_notes_max = FILE_ELF_NOTES_MAX;
+ ms->regex_max = FILE_REGEX_MAX;
return ms;
free:
free(ms);
@@ -540,6 +541,7 @@ free:
private void
apprentice_unmap(struct magic_map *map)
{
+ size_t i;
if (map == NULL)
return;
@@ -552,6 +554,8 @@ apprentice_unmap(struct magic_map *map)
#endif
case MAP_TYPE_MALLOC:
free(map->p);
+ for (i = 0; i < MAGIC_SETS; i++)
+ free(map->magic[i]);
break;
case MAP_TYPE_USER:
break;
@@ -1288,6 +1292,7 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
file_oomem(ms, sizeof(*map));
return NULL;
}
+ map->type = MAP_TYPE_MALLOC;
/* print silly verbose header for USG compat. */
if (action == FILE_CHECK)
@@ -1348,8 +1353,9 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
}
i = set_text_binary(ms, mset[j].me, mset[j].count, i);
}
- qsort(mset[j].me, mset[j].count, sizeof(*mset[j].me),
- apprentice_sort);
+ if (mset[j].me)
+ qsort(mset[j].me, mset[j].count, sizeof(*mset[j].me),
+ apprentice_sort);
/*
* Make sure that any level 0 "default" line is last
@@ -2555,12 +2561,14 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
case FILE_LEFLOAT:
if (m->reln != 'x') {
char *ep;
+ errno = 0;
#ifdef HAVE_STRTOF
m->value.f = strtof(*p, &ep);
#else
m->value.f = (float)strtod(*p, &ep);
#endif
- *p = ep;
+ if (errno == 0)
+ *p = ep;
}
return 0;
case FILE_DOUBLE:
@@ -2568,17 +2576,22 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
case FILE_LEDOUBLE:
if (m->reln != 'x') {
char *ep;
+ errno = 0;
m->value.d = strtod(*p, &ep);
- *p = ep;
+ if (errno == 0)
+ *p = ep;
}
return 0;
default:
if (m->reln != 'x') {
char *ep;
+ errno = 0;
m->value.q = file_signextend(ms, m,
(uint64_t)strtoull(*p, &ep, 0));
- *p = ep;
- eatsize(p);
+ if (errno == 0) {
+ *p = ep;
+ eatsize(p);
+ }
}
return 0;
}
@@ -2614,6 +2627,7 @@ getstr(struct magic_set *ms, struct magic *m, const char *s, int warn)
case '\0':
if (warn)
file_magwarn(ms, "incomplete escape");
+ s--;
goto out;
case '\t':
@@ -2737,6 +2751,7 @@ getstr(struct magic_set *ms, struct magic *m, const char *s, int warn)
} else
*p++ = (char)c;
}
+ --s;
out:
*p = '\0';
m->vallen = CAST(unsigned char, (p - origp));
@@ -3209,9 +3224,10 @@ file_pstring_length_size(const struct magic *m)
}
}
protected size_t
-file_pstring_get_length(const struct magic *m, const char *s)
+file_pstring_get_length(const struct magic *m, const char *ss)
{
size_t len = 0;
+ const unsigned char *s = (const unsigned char *)ss;
switch (m->str_flags & PSTRING_LEN) {
case PSTRING_1_LE:
diff --git a/contrib/file/src/file.c b/contrib/file/src/file.c
index 44f4cce..fa46b95 100644
--- a/contrib/file/src/file.c
+++ b/contrib/file/src/file.c
@@ -32,7 +32,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: file.c,v 1.165 2015/06/11 12:52:32 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.167 2015/09/11 17:24:09 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -131,6 +131,7 @@ private struct {
{ "elf_phnum", MAGIC_PARAM_ELF_PHNUM_MAX, 0 },
{ "elf_shnum", MAGIC_PARAM_ELF_SHNUM_MAX, 0 },
{ "elf_notes", MAGIC_PARAM_ELF_NOTES_MAX, 0 },
+ { "regex", MAGIC_PARAM_REGEX_MAX, 0 },
};
private char *progname; /* used throughout */
@@ -237,6 +238,7 @@ main(int argc, char *argv[])
if (magic == NULL)
if ((magic = load(magicfile, flags)) == NULL)
return 1;
+ applyparam(magic);
e |= unwrap(magic, optarg);
++didsomefiles;
break;
diff --git a/contrib/file/src/file.h b/contrib/file/src/file.h
index 1b4ef6f..b0f0cc1 100644
--- a/contrib/file/src/file.h
+++ b/contrib/file/src/file.h
@@ -27,7 +27,7 @@
*/
/*
* file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.168 2015/04/09 20:01:41 christos Exp $
+ * @(#)$File: file.h,v 1.172 2015/09/11 17:24:09 christos Exp $
*/
#ifndef __file_h__
@@ -44,9 +44,11 @@
#define SIZE_T_FORMAT ""
#endif
#define INT64_T_FORMAT "I64"
+ #define INTMAX_T_FORMAT "I64"
#else
#define SIZE_T_FORMAT "z"
#define INT64_T_FORMAT "ll"
+ #define INTMAX_T_FORMAT "j"
#endif
#include <stdio.h> /* Include that here, to make sure __P gets defined */
@@ -300,15 +302,15 @@ struct magic {
#define num_mask _u._mask
#define str_range _u._s._count
#define str_flags _u._s._flags
- /* Words 9-16 */
+ /* Words 9-24 */
union VALUETYPE value; /* either number or string */
- /* Words 17-32 */
+ /* Words 25-40 */
char desc[MAXDESC]; /* description */
- /* Words 33-52 */
+ /* Words 41-60 */
char mimetype[MAXMIME]; /* MIME type */
- /* Words 53-54 */
+ /* Words 61-62 */
char apple[8]; /* APPLE CREATOR/TYPE */
- /* Words 55-63 */
+ /* Words 63-78 */
char ext[64]; /* Popular extensions */
};
@@ -413,11 +415,13 @@ struct magic_set {
uint16_t elf_shnum_max;
uint16_t elf_phnum_max;
uint16_t elf_notes_max;
+ uint16_t regex_max;
#define FILE_INDIR_MAX 15
#define FILE_NAME_MAX 30
#define FILE_ELF_SHNUM_MAX 32768
-#define FILE_ELF_PHNUM_MAX 128
+#define FILE_ELF_PHNUM_MAX 2048
#define FILE_ELF_NOTES_MAX 256
+#define FILE_REGEX_MAX 8192
};
/* Type for Unicode characters */
diff --git a/contrib/file/src/file_opts.h b/contrib/file/src/file_opts.h
index 2e30d06..3d9a7ce 100644
--- a/contrib/file/src/file_opts.h
+++ b/contrib/file/src/file_opts.h
@@ -45,7 +45,7 @@ OPT('0', "print0", 0, " terminate filenames with ASCII NUL\n")
#if defined(HAVE_UTIME) || defined(HAVE_UTIMES)
OPT('p', "preserve-date", 0, " preserve access times on files\n")
#endif
-OPT('P', "parameter", 0, " set file engine parameter limits\n"
+OPT('P', "parameter", 1, " set file engine parameter limits\n"
" indir 15 recursion limit for indirection\n"
" name 30 use limit for name/use magic\n"
" elf_notes 256 max ELF notes processed\n"
diff --git a/contrib/file/src/funcs.c b/contrib/file/src/funcs.c
index 16f2c4e..97d4a0a 100644
--- a/contrib/file/src/funcs.c
+++ b/contrib/file/src/funcs.c
@@ -27,7 +27,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.83 2015/06/16 14:17:37 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.84 2015/09/10 13:32:19 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -204,7 +204,10 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((__u
#ifdef __EMX__
if ((ms->flags & MAGIC_NO_CHECK_APPTYPE) == 0 && inname) {
- switch (file_os2_apptype(ms, inname, buf, nb)) {
+ m = file_os2_apptype(ms, inname, buf, nb);
+ if ((ms->flags & MAGIC_DEBUG) != 0)
+ (void)fprintf(stderr, "[try os2_apptype %d]\n", m);
+ switch (m) {
case -1:
return -1;
case 0:
@@ -216,37 +219,43 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((__u
#endif
#if HAVE_FORK
/* try compression stuff */
- if ((ms->flags & MAGIC_NO_CHECK_COMPRESS) == 0)
- if ((m = file_zmagic(ms, fd, inname, ubuf, nb)) != 0) {
- if ((ms->flags & MAGIC_DEBUG) != 0)
- (void)fprintf(stderr, "zmagic %d\n", m);
+ if ((ms->flags & MAGIC_NO_CHECK_COMPRESS) == 0) {
+ m = file_zmagic(ms, fd, inname, ubuf, nb);
+ if ((ms->flags & MAGIC_DEBUG) != 0)
+ (void)fprintf(stderr, "[try zmagic %d]\n", m);
+ if (m) {
goto done_encoding;
}
+ }
#endif
/* Check if we have a tar file */
- if ((ms->flags & MAGIC_NO_CHECK_TAR) == 0)
- if ((m = file_is_tar(ms, ubuf, nb)) != 0) {
- if ((ms->flags & MAGIC_DEBUG) != 0)
- (void)fprintf(stderr, "tar %d\n", m);
+ if ((ms->flags & MAGIC_NO_CHECK_TAR) == 0) {
+ m = file_is_tar(ms, ubuf, nb);
+ if ((ms->flags & MAGIC_DEBUG) != 0)
+ (void)fprintf(stderr, "[try tar %d]\n", m);
+ if (m) {
if (checkdone(ms, &rv))
goto done;
}
+ }
/* Check if we have a CDF file */
- if ((ms->flags & MAGIC_NO_CHECK_CDF) == 0)
- if ((m = file_trycdf(ms, fd, ubuf, nb)) != 0) {
- if ((ms->flags & MAGIC_DEBUG) != 0)
- (void)fprintf(stderr, "cdf %d\n", m);
+ if ((ms->flags & MAGIC_NO_CHECK_CDF) == 0) {
+ m = file_trycdf(ms, fd, ubuf, nb);
+ if ((ms->flags & MAGIC_DEBUG) != 0)
+ (void)fprintf(stderr, "[try cdf %d]\n", m);
+ if (m) {
if (checkdone(ms, &rv))
goto done;
}
+ }
/* try soft magic tests */
if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0)
- if ((m = file_softmagic(ms, ubuf, nb, 0, NULL, BINTEST,
- looks_text)) != 0) {
- if ((ms->flags & MAGIC_DEBUG) != 0)
- (void)fprintf(stderr, "softmagic %d\n", m);
+ m = file_softmagic(ms, ubuf, nb, 0, NULL, BINTEST, looks_text);
+ if ((ms->flags & MAGIC_DEBUG) != 0)
+ (void)fprintf(stderr, "[try softmagic %d]\n", m);
+ if (m) {
#ifdef BUILTIN_ELF
if ((ms->flags & MAGIC_NO_CHECK_ELF) == 0 && m == 1 &&
nb > 5 && fd != -1) {
@@ -259,10 +268,10 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((__u
* ELF headers that cannot easily * be
* extracted with rules in the magic file.
*/
- if ((m = file_tryelf(ms, fd, ubuf, nb)) != 0)
- if ((ms->flags & MAGIC_DEBUG) != 0)
- (void)fprintf(stderr,
- "elf %d\n", m);
+ m = file_tryelf(ms, fd, ubuf, nb);
+ if ((ms->flags & MAGIC_DEBUG) != 0)
+ (void)fprintf(stderr, "[try elf %d]\n",
+ m);
}
#endif
if (checkdone(ms, &rv))
@@ -272,9 +281,10 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((__u
/* try text properties */
if ((ms->flags & MAGIC_NO_CHECK_TEXT) == 0) {
- if ((m = file_ascmagic(ms, ubuf, nb, looks_text)) != 0) {
- if ((ms->flags & MAGIC_DEBUG) != 0)
- (void)fprintf(stderr, "ascmagic %d\n", m);
+ m = file_ascmagic(ms, ubuf, nb, looks_text);
+ if ((ms->flags & MAGIC_DEBUG) != 0)
+ (void)fprintf(stderr, "[try ascmagic %d]\n", m);
+ if (m) {
if (checkdone(ms, &rv))
goto done;
}
diff --git a/contrib/file/src/gmtime_r.c b/contrib/file/src/gmtime_r.c
index 963dfee..469ec65 100644
--- a/contrib/file/src/gmtime_r.c
+++ b/contrib/file/src/gmtime_r.c
@@ -1,15 +1,15 @@
-/* $File: gmtime_r.c,v 1.1 2015/01/09 19:28:32 christos Exp $ */
+/* $File: gmtime_r.c,v 1.2 2015/07/11 14:41:37 christos Exp $ */
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: gmtime_r.c,v 1.1 2015/01/09 19:28:32 christos Exp $")
+FILE_RCSID("@(#)$File: gmtime_r.c,v 1.2 2015/07/11 14:41:37 christos Exp $")
#endif /* lint */
#include <time.h>
#include <string.h>
/* asctime_r is not thread-safe anyway */
struct tm *
-gmtime_r(const time_t t, struct tm *tm)
+gmtime_r(const time_t *t, struct tm *tm)
{
struct tm *tmp = gmtime(t);
if (tmp == NULL)
diff --git a/contrib/file/src/localtime_r.c b/contrib/file/src/localtime_r.c
index 69d78d9..b0d996d 100644
--- a/contrib/file/src/localtime_r.c
+++ b/contrib/file/src/localtime_r.c
@@ -1,15 +1,15 @@
-/* $File: localtime_r.c,v 1.1 2015/01/09 19:28:32 christos Exp $ */
+/* $File: localtime_r.c,v 1.2 2015/07/11 14:41:37 christos Exp $ */
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: localtime_r.c,v 1.1 2015/01/09 19:28:32 christos Exp $")
+FILE_RCSID("@(#)$File: localtime_r.c,v 1.2 2015/07/11 14:41:37 christos Exp $")
#endif /* lint */
#include <time.h>
#include <string.h>
/* asctime_r is not thread-safe anyway */
struct tm *
-localtime_r(const time_t t, struct tm *tm)
+localtime_r(const time_t *t, struct tm *tm)
{
struct tm *tmp = localtime(t);
if (tmp == NULL)
diff --git a/contrib/file/src/magic.c b/contrib/file/src/magic.c
index bc8c344..87ac1cb 100644
--- a/contrib/file/src/magic.c
+++ b/contrib/file/src/magic.c
@@ -33,7 +33,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: magic.c,v 1.93 2015/04/15 23:47:58 christos Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.95 2015/09/11 17:24:09 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -137,6 +137,14 @@ _w32_get_magic_relative_to(char **hmagicpath, HINSTANCE module)
PathRemoveFileSpecA(dllpath);
+ if (module) {
+ char exepath[MAX_PATH];
+ GetModuleFileNameA(NULL, exepath, MAX_PATH);
+ PathRemoveFileSpecA(exepath);
+ if (stricmp(exepath, dllpath) == 0)
+ goto out;
+ }
+
sp = strlen(dllpath);
if (sp > 3 && stricmp(&dllpath[sp - 3], "bin") == 0) {
_w32_append_path(hmagicpath,
@@ -595,6 +603,9 @@ magic_setparam(struct magic_set *ms, int param, const void *val)
case MAGIC_PARAM_ELF_NOTES_MAX:
ms->elf_notes_max = (uint16_t)*(const size_t *)val;
return 0;
+ case MAGIC_PARAM_REGEX_MAX:
+ ms->elf_notes_max = (uint16_t)*(const size_t *)val;
+ return 0;
default:
errno = EINVAL;
return -1;
@@ -620,6 +631,9 @@ magic_getparam(struct magic_set *ms, int param, void *val)
case MAGIC_PARAM_ELF_NOTES_MAX:
*(size_t *)val = ms->elf_notes_max;
return 0;
+ case MAGIC_PARAM_REGEX_MAX:
+ *(size_t *)val = ms->regex_max;
+ return 0;
default:
errno = EINVAL;
return -1;
diff --git a/contrib/file/src/magic.h b/contrib/file/src/magic.h
index 0d64316..eab3d3a 100644
--- a/contrib/file/src/magic.h
+++ b/contrib/file/src/magic.h
@@ -80,7 +80,7 @@
#define MAGIC_NO_CHECK_FORTRAN 0x000000 /* Don't check ascii/fortran */
#define MAGIC_NO_CHECK_TROFF 0x000000 /* Don't check ascii/troff */
-#define MAGIC_VERSION 522 /* This implementation */
+#define MAGIC_VERSION 524 /* This implementation */
#ifdef __cplusplus
@@ -113,6 +113,7 @@ int magic_errno(magic_t);
#define MAGIC_PARAM_ELF_PHNUM_MAX 2
#define MAGIC_PARAM_ELF_SHNUM_MAX 3
#define MAGIC_PARAM_ELF_NOTES_MAX 4
+#define MAGIC_PARAM_REGEX_MAX 5
int magic_setparam(magic_t, int, const void *);
int magic_getparam(magic_t, int, void *);
diff --git a/contrib/file/src/magic.h.in b/contrib/file/src/magic.h.in
index 500bdbd..1e567cd 100644
--- a/contrib/file/src/magic.h.in
+++ b/contrib/file/src/magic.h.in
@@ -113,6 +113,7 @@ int magic_errno(magic_t);
#define MAGIC_PARAM_ELF_PHNUM_MAX 2
#define MAGIC_PARAM_ELF_SHNUM_MAX 3
#define MAGIC_PARAM_ELF_NOTES_MAX 4
+#define MAGIC_PARAM_REGEX_MAX 5
int magic_setparam(magic_t, int, const void *);
int magic_getparam(magic_t, int, void *);
diff --git a/contrib/file/src/print.c b/contrib/file/src/print.c
index 07ae8f6..0d52290 100644
--- a/contrib/file/src/print.c
+++ b/contrib/file/src/print.c
@@ -32,7 +32,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: print.c,v 1.79 2015/01/09 19:28:32 christos Exp $")
+FILE_RCSID("@(#)$File: print.c,v 1.80 2015/07/16 14:28:57 christos Exp $")
#endif /* lint */
#include <string.h>
@@ -156,26 +156,26 @@ file_mdump(struct magic *m)
case FILE_BEDATE:
case FILE_MEDATE:
(void)fprintf(stderr, "%s,",
- file_fmttime(m->value.l, FILE_T_LOCAL, tbuf));
+ file_fmttime(m->value.l, 0, tbuf));
break;
case FILE_LDATE:
case FILE_LELDATE:
case FILE_BELDATE:
case FILE_MELDATE:
(void)fprintf(stderr, "%s,",
- file_fmttime(m->value.l, 0, tbuf));
+ file_fmttime(m->value.l, FILE_T_LOCAL, tbuf));
break;
case FILE_QDATE:
case FILE_LEQDATE:
case FILE_BEQDATE:
(void)fprintf(stderr, "%s,",
- file_fmttime(m->value.q, FILE_T_LOCAL, tbuf));
+ file_fmttime(m->value.q, 0, tbuf));
break;
case FILE_QLDATE:
case FILE_LEQLDATE:
case FILE_BEQLDATE:
(void)fprintf(stderr, "%s,",
- file_fmttime(m->value.q, 0, tbuf));
+ file_fmttime(m->value.q, FILE_T_LOCAL, tbuf));
break;
case FILE_QWDATE:
case FILE_LEQWDATE:
diff --git a/contrib/file/src/readelf.c b/contrib/file/src/readelf.c
index 9631591..2a7fc01 100644
--- a/contrib/file/src/readelf.c
+++ b/contrib/file/src/readelf.c
@@ -27,7 +27,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.120 2015/06/16 14:18:07 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.122 2015/09/10 13:59:32 christos Exp $")
#endif
#ifdef BUILTIN_ELF
@@ -1052,11 +1052,14 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
/* Things we can determine when we seek */
switch (xsh_type) {
case SHT_NOTE:
- if (xsh_size + (uintmax_t)xsh_offset > (uintmax_t)fsize) {
+ if ((uintmax_t)(xsh_size + xsh_offset) >
+ (uintmax_t)fsize) {
if (file_printf(ms,
- ", note offset/size 0x%jx+0x%jx exceeds"
- " file size 0x%jx", (uintmax_t)xsh_offset,
- (uintmax_t)xsh_size, (uintmax_t)fsize) == -1)
+ ", note offset/size 0x%" INTMAX_T_FORMAT
+ "x+0x%" INTMAX_T_FORMAT "x exceeds"
+ " file size 0x%" INTMAX_T_FORMAT "x",
+ (uintmax_t)xsh_offset, (uintmax_t)xsh_size,
+ (uintmax_t)fsize) == -1)
return -1;
return 0;
}
@@ -1065,7 +1068,8 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
" for note");
return -1;
}
- if (pread(fd, nbuf, xsh_size, xsh_offset) < (ssize_t)xsh_size) {
+ if (pread(fd, nbuf, xsh_size, xsh_offset) <
+ (ssize_t)xsh_size) {
file_badread(ms);
free(nbuf);
return -1;
diff --git a/contrib/file/src/softmagic.c b/contrib/file/src/softmagic.c
index 15a092f..84a8932 100644
--- a/contrib/file/src/softmagic.c
+++ b/contrib/file/src/softmagic.c
@@ -32,7 +32,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.216 2015/06/09 22:17:52 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.218 2015/09/11 17:24:09 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -63,6 +63,22 @@ private void cvt_32(union VALUETYPE *, const struct magic *);
private void cvt_64(union VALUETYPE *, const struct magic *);
#define OFFSET_OOB(n, o, i) ((n) < (o) || (i) > ((n) - (o)))
+#define BE64(p) (((uint64_t)(p)->hq[0]<<56)|((uint64_t)(p)->hq[1]<<48)| \
+ ((uint64_t)(p)->hq[2]<<40)|((uint64_t)(p)->hq[3]<<32)| \
+ ((uint64_t)(p)->hq[4]<<24)|((uint64_t)(p)->hq[5]<<16)| \
+ ((uint64_t)(p)->hq[6]<<8)|((uint64_t)(p)->hq[7]))
+#define LE64(p) (((uint64_t)(p)->hq[7]<<56)|((uint64_t)(p)->hq[6]<<48)| \
+ ((uint64_t)(p)->hq[5]<<40)|((uint64_t)(p)->hq[4]<<32)| \
+ ((uint64_t)(p)->hq[3]<<24)|((uint64_t)(p)->hq[2]<<16)| \
+ ((uint64_t)(p)->hq[1]<<8)|((uint64_t)(p)->hq[0]))
+#define LE32(p) (((uint32_t)(p)->hl[3]<<24)|((uint32_t)(p)->hl[2]<<16)| \
+ ((uint32_t)(p)->hl[1]<<8)|((uint32_t)(p)->hl[0]))
+#define BE32(p) (((uint32_t)(p)->hl[0]<<24)|((uint32_t)(p)->hl[1]<<16)| \
+ ((uint32_t)(p)->hl[2]<<8)|((uint32_t)(p)->hl[3]))
+#define ME32(p) (((uint32_t)(p)->hl[1]<<24)|((uint32_t)(p)->hl[0]<<16)| \
+ ((uint32_t)(p)->hl[3]<<8)|((uint32_t)(p)->hl[2]))
+#define BE16(p) (((uint16_t)(p)->hs[0]<<8)|((uint16_t)(p)->hs[1]))
+#define LE16(p) (((uint16_t)(p)->hs[1]<<8)|((uint16_t)(p)->hs[0]))
/*
* softmagic - lookup one file in parsed, in-memory copy of database
@@ -962,84 +978,65 @@ mconvert(struct magic_set *ms, struct magic *m, int flip)
return 1;
}
case FILE_BESHORT:
- p->h = (short)((p->hs[0]<<8)|(p->hs[1]));
+ p->h = (short)BE16(p);
cvt_16(p, m);
return 1;
case FILE_BELONG:
case FILE_BEDATE:
case FILE_BELDATE:
- p->l = (int32_t)
- ((p->hl[0]<<24)|(p->hl[1]<<16)|(p->hl[2]<<8)|(p->hl[3]));
+ p->l = (int32_t)BE32(p);
cvt_32(p, m);
return 1;
case FILE_BEQUAD:
case FILE_BEQDATE:
case FILE_BEQLDATE:
case FILE_BEQWDATE:
- p->q = (uint64_t)
- (((uint64_t)p->hq[0]<<56)|((uint64_t)p->hq[1]<<48)|
- ((uint64_t)p->hq[2]<<40)|((uint64_t)p->hq[3]<<32)|
- ((uint64_t)p->hq[4]<<24)|((uint64_t)p->hq[5]<<16)|
- ((uint64_t)p->hq[6]<<8)|((uint64_t)p->hq[7]));
+ p->q = (uint64_t)BE64(p);
cvt_64(p, m);
return 1;
case FILE_LESHORT:
- p->h = (short)((p->hs[1]<<8)|(p->hs[0]));
+ p->h = (short)LE16(p);
cvt_16(p, m);
return 1;
case FILE_LELONG:
case FILE_LEDATE:
case FILE_LELDATE:
- p->l = (int32_t)
- ((p->hl[3]<<24)|(p->hl[2]<<16)|(p->hl[1]<<8)|(p->hl[0]));
+ p->l = (int32_t)LE32(p);
cvt_32(p, m);
return 1;
case FILE_LEQUAD:
case FILE_LEQDATE:
case FILE_LEQLDATE:
case FILE_LEQWDATE:
- p->q = (uint64_t)
- (((uint64_t)p->hq[7]<<56)|((uint64_t)p->hq[6]<<48)|
- ((uint64_t)p->hq[5]<<40)|((uint64_t)p->hq[4]<<32)|
- ((uint64_t)p->hq[3]<<24)|((uint64_t)p->hq[2]<<16)|
- ((uint64_t)p->hq[1]<<8)|((uint64_t)p->hq[0]));
+ p->q = (uint64_t)LE64(p);
cvt_64(p, m);
return 1;
case FILE_MELONG:
case FILE_MEDATE:
case FILE_MELDATE:
- p->l = (int32_t)
- ((p->hl[1]<<24)|(p->hl[0]<<16)|(p->hl[3]<<8)|(p->hl[2]));
+ p->l = (int32_t)ME32(p);
cvt_32(p, m);
return 1;
case FILE_FLOAT:
cvt_float(p, m);
return 1;
case FILE_BEFLOAT:
- p->l = ((uint32_t)p->hl[0]<<24)|((uint32_t)p->hl[1]<<16)|
- ((uint32_t)p->hl[2]<<8) |((uint32_t)p->hl[3]);
+ p->l = BE32(p);
cvt_float(p, m);
return 1;
case FILE_LEFLOAT:
- p->l = ((uint32_t)p->hl[3]<<24)|((uint32_t)p->hl[2]<<16)|
- ((uint32_t)p->hl[1]<<8) |((uint32_t)p->hl[0]);
+ p->l = LE32(p);
cvt_float(p, m);
return 1;
case FILE_DOUBLE:
cvt_double(p, m);
return 1;
case FILE_BEDOUBLE:
- p->q = ((uint64_t)p->hq[0]<<56)|((uint64_t)p->hq[1]<<48)|
- ((uint64_t)p->hq[2]<<40)|((uint64_t)p->hq[3]<<32)|
- ((uint64_t)p->hq[4]<<24)|((uint64_t)p->hq[5]<<16)|
- ((uint64_t)p->hq[6]<<8) |((uint64_t)p->hq[7]);
+ p->q = BE64(p);
cvt_double(p, m);
return 1;
case FILE_LEDOUBLE:
- p->q = ((uint64_t)p->hq[7]<<56)|((uint64_t)p->hq[6]<<48)|
- ((uint64_t)p->hq[5]<<40)|((uint64_t)p->hq[4]<<32)|
- ((uint64_t)p->hq[3]<<24)|((uint64_t)p->hq[2]<<16)|
- ((uint64_t)p->hq[1]<<8) |((uint64_t)p->hq[0]);
+ p->q = LE64(p);
cvt_double(p, m);
return 1;
case FILE_REGEX:
@@ -1105,6 +1102,8 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
if (bytecnt == 0 || bytecnt > nbytes - offset)
bytecnt = nbytes - offset;
+ if (bytecnt > ms->regex_max)
+ bytecnt = ms->regex_max;
buf = RCAST(const char *, s) + offset;
end = last = RCAST(const char *, s) + bytecnt + offset;
@@ -1239,27 +1238,24 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
off = q->h;
break;
case FILE_BESHORT:
- off = (short)((q->hs[0]<<8)|(q->hs[1]));
+ off = (short)BE16(q);
break;
case FILE_LESHORT:
- off = (short)((q->hs[1]<<8)|(q->hs[0]));
+ off = (short)LE16(q);
break;
case FILE_LONG:
off = q->l;
break;
case FILE_BELONG:
case FILE_BEID3:
- off = (int32_t)((q->hl[0]<<24)|(q->hl[1]<<16)|
- (q->hl[2]<<8)|(q->hl[3]));
+ off = (int32_t)BE32(q);
break;
case FILE_LEID3:
case FILE_LELONG:
- off = (int32_t)((q->hl[3]<<24)|(q->hl[2]<<16)|
- (q->hl[1]<<8)|(q->hl[0]));
+ off = (int32_t)LE32(q);
break;
case FILE_MELONG:
- off = (int32_t)((q->hl[1]<<24)|(q->hl[0]<<16)|
- (q->hl[3]<<8)|(q->hl[2]));
+ off = (int32_t)ME32(q);
break;
}
if ((ms->flags & MAGIC_DEBUG) != 0)
@@ -1413,8 +1409,7 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
case FILE_BEID3:
if (OFFSET_OOB(nbytes, offset, 4))
return 0;
- lhs = (p->hl[0] << 24) | (p->hl[1] << 16) |
- (p->hl[2] << 8) | p->hl[3];
+ lhs = BE32(p);
if (off) {
switch (m->in_op & FILE_OPS_MASK) {
case FILE_OPAND:
@@ -1451,8 +1446,7 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
case FILE_LEID3:
if (OFFSET_OOB(nbytes, offset, 4))
return 0;
- lhs = (p->hl[3] << 24) | (p->hl[2] << 16) |
- (p->hl[1] << 8) | p->hl[0];
+ lhs = LE32(p);
if (off) {
switch (m->in_op & FILE_OPS_MASK) {
case FILE_OPAND:
@@ -1488,8 +1482,7 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
case FILE_MELONG:
if (OFFSET_OOB(nbytes, offset, 4))
return 0;
- lhs = (p->hl[1] << 24) | (p->hl[0] << 16) |
- (p->hl[3] << 8) | p->hl[2];
+ lhs = ME32(p);
if (off) {
switch (m->in_op & FILE_OPS_MASK) {
case FILE_OPAND:
@@ -1565,9 +1558,9 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
case FILE_LEID3:
case FILE_BEID3:
offset = ((((offset >> 0) & 0x7f) << 0) |
- (((offset >> 8) & 0x7f) << 7) |
- (((offset >> 16) & 0x7f) << 14) |
- (((offset >> 24) & 0x7f) << 21));
+ (((offset >> 8) & 0x7f) << 7) |
+ (((offset >> 16) & 0x7f) << 14) |
+ (((offset >> 24) & 0x7f) << 21));
if ((ms->flags & MAGIC_DEBUG) != 0)
fprintf(stderr, "id3 offs=%u\n", offset);
break;
OpenPOWER on IntegriCloud