From: Christos Zoulas Date: Fri, 28 Mar 2003 21:02:03 +0000 (+0000) Subject: don't pack stuff, and make magic properly aligned for 64 bit archs. X-Git-Tag: FILE4_02~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a49ac82fd648dd57e2b2424dd81a276aae573715;p=file don't pack stuff, and make magic properly aligned for 64 bit archs. --- diff --git a/src/apprentice.c b/src/apprentice.c index 7daed58e..01112840 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -50,7 +50,7 @@ #endif #ifndef lint -FILE_RCSID("@(#)$Id: apprentice.c,v 1.56 2003/03/26 16:25:25 christos Exp $") +FILE_RCSID("@(#)$Id: apprentice.c,v 1.57 2003/03/28 21:02:03 christos Exp $") #endif /* lint */ #define EATAB {while (isascii((unsigned char) *l) && \ @@ -143,6 +143,13 @@ apprentice_1(struct magic_set *ms, const char *fn, int action, int rv = -1; int mapped; + if (sizeof(*magic) != FILE_MAGICSIZE) { + file_error(ms, "Magic element size %lu != %lu", + (unsigned long)sizeof(*magic), + (unsigned long)FILE_MAGICSIZE); + return -1; + } + if (action == FILE_COMPILE) { rv = apprentice_file(ms, &magic, &nmagic, fn, action); if (rv == 0) { diff --git a/src/file.h b/src/file.h index 47778060..8fbc0f21 100644 --- a/src/file.h +++ b/src/file.h @@ -32,7 +32,7 @@ */ /* * file.h - definitions for file(1) program - * @(#)$Id: file.h,v 1.52 2003/03/27 18:34:21 christos Exp $ + * @(#)$Id: file.h,v 1.53 2003/03/28 21:02:03 christos Exp $ */ #ifndef __file_h__ @@ -70,28 +70,25 @@ # define HOWMANY 65536 /* how much of the file to look at */ #endif #define MAXMAGIS 4096 /* max entries in /etc/magic */ -#define MAXDESC 50 /* max leng of text description */ +#define MAXDESC 64 /* max leng of text description */ #define MAXstring 32 /* max leng of "string" types */ #define MAGICNO 0xF11E041C -#define VERSIONNO 1 +#define VERSIONNO 2 +#define FILE_MAGICSIZE (32 * 4) #define FILE_CHECK 1 #define FILE_COMPILE 2 -#ifndef __GNUC__ -#ifndef __attribute__ -#define __attribute__(a) -#endif -#endif - struct magic { + /* Word 1 */ uint16_t cont_level; /* level of ">" */ uint8_t nospflag; /* supress space character */ uint8_t flag; #define INDIR 1 /* if '>(...)' appears, */ #define UNSIGNED 2 /* comparison is unsigned */ #define OFFADD 4 /* if '>&' appears, */ + /* Word 2 */ uint8_t reln; /* relation (0=eq, '>'=gt, etc) */ uint8_t vallen; /* length of string value, if any */ uint8_t type; /* int, short, long or string. */ @@ -112,8 +109,11 @@ struct magic { #define FILE_BELDATE 15 #define FILE_LELDATE 16 #define FILE_REGEX 17 + /* Word 3 */ uint8_t in_op; /* operator for indirection */ uint8_t mask_op; /* operator for mask */ + uint8_t dummy1; + uint8_t dummy2; #define FILE_OPS "&|^+-*%/" #define FILE_OPAND 0 #define FILE_OPOR 1 @@ -124,8 +124,17 @@ struct magic { #define FILE_OPDIVIDE 6 #define FILE_OPMODULO 7 #define FILE_OPINVERSE 0x80 + /* Word 4 */ int32_t offset; /* offset to magic number */ + /* Word 5 */ int32_t in_offset; /* offset from indirection */ + /* Word 6 */ + uint32_t mask; /* mask before comparison with value */ + /* Word 7 */ + uint32_t dummy3; + /* Word 8 */ + uint32_t dummp4; + /* Words 9-16 */ union VALUETYPE { uint8_t b; uint16_t h; @@ -135,9 +144,9 @@ struct magic { uint8_t hs[2]; /* 2 bytes of a fixed-endian "short" */ uint8_t hl[4]; /* 4 bytes of a fixed-endian "long" */ } value; /* either number or string */ - uint32_t mask; /* mask before comparison with value */ + /* Words 17..31 */ char desc[MAXDESC]; /* description */ -} __attribute__((__packed__)); +}; #define BIT(A) (1 << (A)) #define STRING_IGNORE_LOWERCASE BIT(0)