splint fiddles.
authorjbj <devnull@localhost>
Fri, 24 Jan 2003 19:41:55 +0000 (19:41 +0000)
committerjbj <devnull@localhost>
Fri, 24 Jan 2003 19:41:55 +0000 (19:41 +0000)
CVS patchset: 6025
CVS date: 2003/01/24 19:41:55

14 files changed:
file/.splintrc
file/Makefile.am
file/apprentice.c
file/ascmagic.c
file/compress.c
file/file.c
file/file.h
file/fsmagic.c
file/print.c
file/readelf.c
file/readelf.h
file/softmagic.c
file/system.h
file/tar.h

index 2e758c9..015efeb 100644 (file)
@@ -1,4 +1,4 @@
--I. -DHAVE_CONFIG_H -DSTDC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGFILE_SOURCE -D__STDC__=1 -DHAVE_STRUCT_STAT_ST_RDEV -DSIZEOF_UINT64_T=8
+-I. -I../zlib -DHAVE_CONFIG_H -DSTDC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGFILE_SOURCE -D__STDC__=1 -DHAVE_STRUCT_STAT_ST_RDEV -DSIZEOF_UINT64_T=8
 
 #+partial
 +forcehints
 +strict                        # lclint level
 
 # --- in progress
--compmempass           # 7
++bounds
+
+-fielduse
+-exportfcn
 -exportheader          # 50
--formatconst           # 1
--globstate             # 3
--macroredef            # 1 tar.h
--nullderef             # 1
--nullpass              # 5
--nullptrarith          # 1
--redef                 # 1 tar.h
--sizeoftype            # 14
+-exporttype
 
 # --- not-yet at strict level
 -bitwisesigned         # 86
index 6741db3..d1351ef 100644 (file)
@@ -238,3 +238,7 @@ listobjs:
 lint:
        $(LINT)  $(DEFS) $(INCLUDES) $(file_SOURCES) $(libfmagic_la_SOURCES) $(pkginc_HEADERS) $(noinst_HEADERS)
 
+.PHONY: sources
+sources:
+       @echo $(libfmagic_la_SOURCES:%=file/%)
+
index 7e6079c..9c36dac 100644 (file)
@@ -119,6 +119,7 @@ signextend(struct magic *m, uint32_t v)
 /*
  * eatsize(): Eat the size spec from a number [eg. 10UL]
  */
+/*@-bounds@*/
 static void
 eatsize(/*@out@*/ char **p)
        /*@modifies *p @*/
@@ -142,6 +143,7 @@ eatsize(/*@out@*/ char **p)
 
        *p = l;
 }
+/*@=bounds@*/
 
 /* Single hex char to int; -1 if not a hex char. */
 static int
@@ -165,6 +167,8 @@ hextoint(int c)
  * Copy the converted version to "p", returning its length in *slen.
  * Return updated scan pointer as function result.
  */
+/*@-shiftimplementation@*/
+/*@-bounds@*/
 static char *
 getstr(/*@returned@*/ char *s, char *p, int plen, /*@out@*/ int *slen)
        /*@globals fileSystem @*/
@@ -264,12 +268,15 @@ out:
        *slen = p - origp;
        return s;
 }
+/*@=bounds@*/
+/*@=shiftimplementation@*/
 
 /* 
  * Read a numeric value from a pointer, into the value union of a magic 
  * pointer, according to the magic type.  Update the string pointer to point 
  * just after the number read.  Return 0 for success, non-zero for failure.
  */
+/*@-bounds@*/
 static int
 getvalue(struct magic *m, /*@out@*/ char **p)
        /*@globals fileSystem @*/
@@ -287,10 +294,12 @@ getvalue(struct magic *m, /*@out@*/ char **p)
                }
        return 0;
 }
+/*@=bounds@*/
 
 /*
  * parse one line from magic file, put into magic[index++] if valid
  */
+/*@-bounds@*/
 static int
 parse(/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp,
                char *l, int action)
@@ -648,6 +657,7 @@ GetDesc:
        ++(*nmagicp);           /* make room for next */
        return 0;
 }
+/*@=bounds@*/
 
 /*
  * Print a string containing C character escapes.
@@ -708,6 +718,7 @@ showstr(FILE *fp, const char *s, int len)
 /*
  * swap a short
  */
+/*@-bounds@*/
 static uint16_t
 swap2(uint16_t sv)
        /*@*/
@@ -719,10 +730,12 @@ swap2(uint16_t sv)
        d[1] = s[0];
        return rv;
 }
+/*@=bounds@*/
 
 /*
  * swap an int
  */
+/*@-bounds@*/
 static uint32_t
 swap4(uint32_t sv)
        /*@*/
@@ -736,6 +749,7 @@ swap4(uint32_t sv)
        d[3] = s[0];
        return rv;
 }
+/*@=bounds@*/
 
 /*
  * byteswap a single magic entry
@@ -755,6 +769,7 @@ void bs1(struct magic *m)
 /*
  * Byteswap an mmap'ed file if needed
  */
+/*@-bounds@*/
 static void
 byteswap(/*@null@*/ struct magic *m, uint32_t nmagic)
        /*@modifies m @*/
@@ -764,6 +779,7 @@ byteswap(/*@null@*/ struct magic *m, uint32_t nmagic)
        for (i = 0; i < nmagic; i++)
                bs1(&m[i]);
 }
+/*@=bounds@*/
 
 /*
  * make a dbname
@@ -786,6 +802,7 @@ mkdbname(const char *fn)
  * parse from a file
  * const char *fn: name of magic file
  */
+/*@-bounds@*/
 static int
 apprentice_file(fmagic fm, /*@out@*/ struct magic **magicp,
                /*@out@*/ uint32_t *nmagicp, const char *fn, int action)
@@ -833,10 +850,12 @@ apprentice_file(fmagic fm, /*@out@*/ struct magic **magicp,
        }
        return errs;
 }
+/*@=bounds@*/
 
 /*
  * handle an mmaped file.
  */
+/*@-bounds@*/
 static int
 apprentice_compile(/*@unused@*/ const fmagic fm,
                /*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp,
@@ -882,10 +901,12 @@ apprentice_compile(/*@unused@*/ const fmagic fm,
        (void)close(fd);
        return 0;
 }
+/*@=bounds@*/
 
 /*
  * handle a compiled file.
  */
+/*@-bounds@*/
 static int
 apprentice_map(/*@unused@*/ const fmagic fm,
                /*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp,
@@ -932,6 +953,8 @@ apprentice_map(/*@unused@*/ const fmagic fm,
        (void)close(fd);
        fd = -1;
        ptr = (uint32_t *) *magicp;
+       if (ptr == NULL)        /* XXX can't happen */
+               goto errxit;
        if (*ptr != MAGICNO) {
                if (swap4(*ptr) != MAGICNO) {
                        (void)fprintf(stderr, "%s: Bad magic in `%s'\n",
@@ -974,6 +997,7 @@ errxit:
 /*@=branchstate@*/
        return -1;
 }
+/*@=bounds@*/
 
 /*
  * Handle one file.
index 70f6195..37ef00b 100644 (file)
@@ -55,6 +55,7 @@ FILE_RCSID("@(#)Id: ascmagic.c,v 1.32 2002/07/03 18:26:37 christos Exp ")
  *
  * Result is -1 if the field is invalid (all blank, or nonoctal).
  */
+/*@-bounds@*/
 static int
 from_oct(int digs, char *where)
        /*@*/
@@ -67,16 +68,19 @@ from_oct(int digs, char *where)
                        return -1;              /* All blank field */
        }
        value = 0;
+/*@-shiftimplementation@*/
        while (digs > 0 && isodigit(*where)) {  /* Scan til nonoctal */
                value = (value << 3) | (*where++ - '0');
                --digs;
        }
+/*@=shiftimplementation@*/
 
        if (digs > 0 && *where && !isspace((unsigned char)*where))
                return -1;                      /* Ended on non-space/nul */
 
        return value;
 }
+/*@=bounds@*/
 
 /*
  * Return 
@@ -101,7 +105,10 @@ is_tar(const fmagic fm)
 
        sum = 0;
        p = header->charptr;
-       for (i = sizeof(union record); --i >= 0;) {
+/*@-sizeoftype@*/
+       for (i = sizeof(union record); --i >= 0;)
+/*@=sizeoftype@*/
+       {
                /*
                 * We can't use unsigned char here because of old compilers,
                 * e.g. V7.
@@ -117,7 +124,7 @@ is_tar(const fmagic fm)
        if (sum != recsum)
                return 0;       /* Not a tar archive */
        
-       if (!strcmp(header->header.magic, TMAGIC)) 
+       if (!strcmp(header->header.magic, TARMAGIC)) 
                return 2;               /* Unix Standard tar archive */
 
        return 1;                       /* Old fashioned tar archive */
@@ -208,6 +215,7 @@ static char text_chars[256] = {
        I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I   /* 0xfX */
 };
 
+/*@-bounds@*/
 static int
 looks_ascii(const unsigned char *buf, int nb,
                /*@out@*/ unichar *ubuf, /*@out@*/ int *ulen)
@@ -228,7 +236,9 @@ looks_ascii(const unsigned char *buf, int nb,
 
        return 1;
 }
+/*@=bounds@*/
 
+/*@-bounds@*/
 static int
 looks_latin1(const unsigned char *buf, int nb,
                /*@out@*/ unichar *ubuf, /*@out@*/ int *ulen)
@@ -249,7 +259,9 @@ looks_latin1(const unsigned char *buf, int nb,
 
        return 1;
 }
+/*@=bounds@*/
 
+/*@-bounds@*/
 static int
 looks_extended(const unsigned char *buf, int nb,
                /*@out@*/ unichar *ubuf, /*@out@*/ int *ulen)
@@ -270,7 +282,9 @@ looks_extended(const unsigned char *buf, int nb,
 
        return 1;
 }
+/*@=bounds@*/
 
+/*@-bounds@*/
 static int
 looks_utf8(const unsigned char *buf, int nb,
                /*@out@*/ unichar *ubuf, /*@out@*/ int *ulen)
@@ -334,7 +348,9 @@ looks_utf8(const unsigned char *buf, int nb,
 done:
        return gotone;   /* don't claim it's UTF-8 if it's all 7-bit */
 }
+/*@=bounds@*/
 
+/*@-bounds@*/
 static int
 looks_unicode(const unsigned char *buf, int nb,
                /*@out@*/ unichar *ubuf, /*@out@*/ int *ulen)
@@ -371,6 +387,7 @@ looks_unicode(const unsigned char *buf, int nb,
 
        return 1;
 }
+/*@=bounds@*/
 
 #undef F
 #undef T
@@ -456,6 +473,7 @@ static unsigned char ebcdic_1047_to_8859[] = {
 /*
  * Copy buf[0 ... nb-1] into out[], translating EBCDIC to ASCII.
  */
+/*@-bounds@*/
 static void
 from_ebcdic(const unsigned char *buf, int nb, /*@out@*/ unsigned char *otp)
        /*@modifies *otp @*/
@@ -466,7 +484,9 @@ from_ebcdic(const unsigned char *buf, int nb, /*@out@*/ unsigned char *otp)
                otp[i] = ebcdic_to_ascii[buf[i]];
        }
 }
+/*@=bounds@*/
 
+/*@-bounds@*/
 static int
 fmagicAMatch(const unsigned char *s, const unichar *us, int ulen)
        /*@*/
@@ -483,8 +503,10 @@ fmagicAMatch(const unsigned char *s, const unichar *us, int ulen)
        else
                return 1;
 }
+/*@=bounds@*/
 
 /* int nb: size actually read */
+/*@-bounds@*/
 int
 fmagicA(fmagic fm)
 {
@@ -636,7 +658,10 @@ fmagicA(fmagic fm)
                /*
                 * compare the word thus isolated against the token list
                 */
-               for (p = names; p < names + NNAMES; p++) {
+/*@-sizeoftype@*/
+               for (p = names; p < names + NNAMES; p++)
+/*@=sizeoftype@*/
+               {
                        if (p->name == NULL)
                                /*@innerbreak@*/ break;
                        if (fmagicAMatch(p->name, ubuf + i, end - i)) {
@@ -745,3 +770,4 @@ subtype_identified:
 
        return 1;
 }
+/*@=bounds@*/
index 848915f..533fdc9 100644 (file)
@@ -159,6 +159,7 @@ pipe2file(int fd, void *startbuf, size_t nbytes)
 #define FNAME          (1 << 3)
 #define FCOMMENT       (1 << 4)
 
+/*@-bounds@*/
 static int
 uncompressgzipped(const unsigned char *old,
                /*@out@*/ unsigned char **newch, int n)
@@ -195,9 +196,11 @@ uncompressgzipped(const unsigned char *old,
        z.zfree = NULL;
        z.opaque = NULL;
 
+/*@-sizeoftype@*/
 /*@-type@*/
        rc = inflateInit2(&z, -15);
 /*@=type@*/
+/*@=sizeoftype@*/
        if (rc != Z_OK) {
                (void) fprintf(stderr,"%s: zlib: %s\n", __progname, z.msg);
                return 0;
@@ -221,8 +224,10 @@ uncompressgzipped(const unsigned char *old,
 
        return n;
 }
+/*@=bounds@*/
 #endif
 
+/*@-bounds@*/
 static int
 uncompressbuf(int method, const unsigned char *old,
                /*@out@*/ unsigned char **newch, int n)
@@ -293,6 +298,7 @@ errxit:
        /*@notreached@*/
        return 0;
 }
+/*@=bounds@*/
 
 /*
  * compress routines:
@@ -309,8 +315,10 @@ fmagicZ(fmagic fm)
        int i;
 
        for (i = 0; i < ncompr; i++) {
+/*@-boundsread@*/
                if (nb < compr[i].maglen)
                        continue;
+/*@=boundsread@*/
                if (memcmp(buf, compr[i].magic, compr[i].maglen) == 0 &&
                    (newsize = uncompressbuf(i, buf, &newbuf, nb)) != 0) {
                        fm->buf = newbuf;
index f2f6803..ee69d21 100644 (file)
@@ -56,6 +56,7 @@ static        int     nobuffer = 0;   /* Do not buffer stdout */
 /*
  * unwrap -- read a file of filenames, do each one.
  */
+/*@-bounds@*/
 static void
 unwrap(fmagic fm, char *fn)
        /*@globals fileSystem, internalState @*/
@@ -84,7 +85,10 @@ unwrap(fmagic fm, char *fn)
                rewind(f);
        }
 
-       while (fgets(buf, sizeof(buf), f) != NULL) {
+/*@-nullpass@*/        /* LCL: buf is null??? */
+       while (fgets(buf, sizeof(buf), f) != NULL)
+/*@=nullpass@*/
+       {
                buf[strlen(buf)-1] = '\0';
                fm->obp = fm->obuf;
                *fm->obp = '\0';
@@ -97,6 +101,7 @@ unwrap(fmagic fm, char *fn)
 
        (void) fclose(f);
 }
+/*@=bounds@*/
 
 /*@exits@*/
 static void
@@ -147,6 +152,7 @@ help(void)
 /*
  * main - parse arguments and handle options
  */
+/*@-bounds@*/
 int
 main(int argc, char **argv)
        /*@globals global_fmagic, nobuffer,
@@ -306,7 +312,9 @@ main(int argc, char **argv)
                usage();
 
        if (!app) {
+/*@-nullpass@*/ /* FIX: fm->magicfile may be null */
                ret = fmagicSetup(fm, fm->magicfile, action);
+/*@=nullpass@*/
                if (action)
                        exit(ret);
                app = 1;
@@ -341,3 +349,4 @@ main(int argc, char **argv)
 
        return 0;
 }
+/*@=bounds@*/
index 8051ba3..72b9e8c 100644 (file)
@@ -29,6 +29,8 @@
 #ifndef __file_h__
 #define __file_h__
 
+/*@-redef@*/
+
 #ifndef HOWMANY
 # define HOWMANY 65536         /* how much of the file to look at */
 #endif
@@ -218,4 +220,5 @@ extern int pipe2file(int fd, void *startbuf, size_t nbytes)
 }
 #endif
 
+/*@=redef@*/
 #endif /* __file_h__ */
index c4cfc04..81e7a0e 100644 (file)
@@ -33,6 +33,7 @@ FILE_RCSID("@(#)Id: fsmagic.c,v 1.36 2002/07/03 19:00:41 christos Exp ")
 
 /*@access fmagic @*/
 
+/*@-bounds@*/
 int
 fmagicD(fmagic fm)
 {
@@ -97,8 +98,10 @@ fmagicD(fmagic fm)
                        dv_unit(st->st_rdev),
                        dv_subunit(st->st_rdev));
 # else
+/*@-shiftimplementation@*/
                fmagicPrintf(fm, "character special (%ld/%ld)",
                        (long) major(st->st_rdev), (long) minor(st->st_rdev));
+/*@=shiftimplementation@*/
 # endif
 #else
                fmagicPrintf(fm, "character special");
@@ -121,8 +124,10 @@ fmagicD(fmagic fm)
                        dv_unit(st->st_rdev),
                        dv_subunit(st->st_rdev));
 # else
+/*@-shiftimplementation@*/
                fmagicPrintf(fm, "block special (%ld/%ld)",
                        (long) major(st->st_rdev), (long) minor(st->st_rdev));
+/*@=shiftimplementation@*/
 # endif
 #else
                fmagicPrintf(fm, "block special");
@@ -226,6 +231,7 @@ fmagicD(fmagic fm)
        }
        return 0;
 }
+/*@=bounds@*/
 
 int
 fmagicF(fmagic fm, int zfl)
@@ -264,6 +270,7 @@ fmagicF(fmagic fm, int zfl)
 /*
  * fmagicProcess - process input file
  */
+/*@-bounds@*/
 int
 fmagicProcess(fmagic fm, const char *fn, int wid)
 {
@@ -375,3 +382,4 @@ exit:
        fm->nb = 0;
        return ret;
 }
+/*@=bounds@*/
index 490525c..6a18b8b 100644 (file)
@@ -55,8 +55,10 @@ mdump(struct magic *m)
        static const char optyp[] = { '@', '&', '|', '^', '+', '-', 
                                      '*', '/', '%' };
        (void) fputc('[', stderr);
+/*@-formatconst@*/
        (void) fprintf(stderr, ">>>>>>>> %d" + 8 - (m->cont_level & 7),
                       m->offset);
+/*@=formatconst@*/
 
        if (m->flag & INDIR) {
                (void) fprintf(stderr, "(%s,",
@@ -171,6 +173,9 @@ magwarn(const char *f, ...)
        (void) vfprintf(stderr, f, va);
        va_end(va);
        (void) fputc('\n', stderr);
+/*@-globstate@*/ /* FIX: __progname might be null */
+       return;
+/*@=globstate@*/
 }
 
 void
@@ -181,7 +186,9 @@ fmagicPrintf(const fmagic fm, const char *f, ...)
        int rc;
 
        va_start(va, f);
+/*@-boundswrite@*/
        rc = vsnprintf(fm->obp, fm->nob, f, va);
+/*@=boundswrite@*/
        va_end(va);
 
        fm->obuf[sizeof(fm->obuf)-1] = '\0';
@@ -195,7 +202,8 @@ fmagicPrintf(const fmagic fm, const char *f, ...)
 char *
 fmttime(long v, int local)
 {
-       char *pp, *rt;
+       char *pp = "???";
+       char *rt;
        time_t t = (time_t)v;
        struct tm *tm;
 
@@ -218,7 +226,8 @@ fmttime(long v, int local)
                if (daylight)
                        t += 3600;
                tm = gmtime(&t);
-               pp = asctime(tm);
+               if (tm != NULL)
+                       pp = asctime(tm);
        }
 
 /*@-modobserver@*/
index b5abf84..cb28f33 100644 (file)
@@ -9,6 +9,7 @@ FILE_RCSID("@(#)Id: readelf.c,v 1.22 2002/07/03 18:26:38 christos Exp ")
 
 /*@access fmagic @*/
 
+/*@-bounds@*/
 static uint16_t
 getu16(const fmagic fm, uint16_t value)
        /*@*/
@@ -76,6 +77,7 @@ getu64(const fmagic fm, uint64_t value)
        } else
                return value;
 }
+/*@=bounds@*/
 
 #define sh_addr                (fm->cls == ELFCLASS32          \
                         ? (void *) &sh32               \
@@ -111,6 +113,7 @@ getu64(const fmagic fm, uint64_t value)
                         ? prpsoffsets32[i]             \
                         : prpsoffsets64[i])
 
+/*@-bounds@*/
 static void
 doshn(fmagic fm, off_t off, int num, size_t size)
        /*@globals fileSystem @*/
@@ -136,12 +139,14 @@ doshn(fmagic fm, off_t off, int num, size_t size)
        }
        fmagicPrintf(fm, ", stripped");
 }
+/*@=bounds@*/
 
 /*
  * Look through the program headers of an executable image, searching
  * for a PT_INTERP section; if one is found, it's dynamically linked,
  * otherwise it's statically linked.
  */
+/*@-bounds@*/
 static void
 dophn_exec(fmagic fm, off_t off, int num, size_t size)
        /*@globals fileSystem @*/
@@ -215,7 +220,7 @@ dophn_exec(fmagic fm, off_t off, int num, size_t size)
                                        /*
                                         * We're out of note headers.
                                         */
-                                       break;
+                                       /*@innerbreak@*/ break;
                                }
 
                                if (offset + nh_descsz >= bufsize)
@@ -301,6 +306,7 @@ dophn_exec(fmagic fm, off_t off, int num, size_t size)
        }
        fmagicPrintf(fm, ", %s linked%s", linking_style, shared_libraries);
 }
+/*@=bounds@*/
 
 #ifdef ELFCORE
 /*@unchecked@*/ /*@observer@*/
@@ -353,6 +359,7 @@ static const char *os_style_names[] = {
        "NetBSD",
 };
 
+/*@-bounds@*/
 static void
 dophn_core(fmagic fm, off_t off, int num, size_t size)
        /*@globals fileSystem @*/
@@ -556,15 +563,19 @@ dophn_core(fmagic fm, off_t off, int num, size_t size)
                }
        }
 }
+/*@=bounds@*/
 #endif
 
+/*@-bounds@*/
 void
 fmagicE(fmagic fm)
 {
+/*@-sizeoftype@*/
        union {
                int32_t l;
                char c[sizeof (int32_t)];
        } u;
+/*@=sizeoftype@*/
 
        /*
         * If we can't seek, it must be a pipe, socket or fifo.
@@ -588,13 +599,15 @@ fmagicE(fmagic fm)
 
        if (fm->cls == ELFCLASS32) {
                Elf32_Ehdr elfhdr;
-               if (fm->nb <= sizeof (Elf32_Ehdr))
+               if (fm->nb <= sizeof (elfhdr))
                        return;
 
 
                u.l = 1;
                (void) memcpy(&elfhdr, fm->buf, sizeof elfhdr);
+/*@-sizeoftype@*/
                fm->swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[EI_DATA];
+/*@=sizeoftype@*/
 
                if (getu16(fm, elfhdr.e_type) == ET_CORE) 
 #ifdef ELFCORE
@@ -622,13 +635,14 @@ fmagicE(fmagic fm)
 
         if (fm->cls == ELFCLASS64) {
                Elf64_Ehdr elfhdr;
-               if (fm->nb <= sizeof (Elf64_Ehdr))
+               if (fm->nb <= sizeof (elfhdr))
                        return;
 
-
                u.l = 1;
                (void) memcpy(&elfhdr, fm->buf, sizeof elfhdr);
+/*@-sizeoftype@*/
                fm->swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[EI_DATA];
+/*@=sizeoftype@*/
 
                if (getu16(fm, elfhdr.e_type) == ET_CORE) 
 #ifdef ELFCORE
@@ -667,4 +681,5 @@ fmagicE(fmagic fm)
                return;
        }
 }
+/*@=bounds@*/
 #endif /* BUILTIN_ELF */
index 4fb5d68..d591043 100644 (file)
@@ -1,6 +1,9 @@
+/*     $NetBSD: readelf.h,v 1.9 2002/05/18 07:00:47 pooka Exp $        */
+/*@-redef@*/
+
 /*
  * readelf.h 
- * @(#)Id: readelf.h,v 1.7 1999/02/14 17:16:11 christos Exp 
+ * @(#)Id: readelf.h,v 1.9 2002/05/16 18:45:56 christos Exp 
  *
  * Provide elf data structures for non-elf machines, allowing file
  * non-elf hosts to determine if an elf binary is stripped.
@@ -9,6 +12,10 @@
 #ifndef __fake_elf_h__
 #define __fake_elf_h__
 
+#if HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
 typedef uint32_t       Elf32_Addr;
 typedef uint32_t       Elf32_Off;
 typedef uint16_t       Elf32_Half;
@@ -31,6 +38,7 @@ typedef uint8_t               Elf64_Char;
 
 #define EI_NIDENT      16
 
+/*@-matchfields@*/
 typedef struct {
     Elf32_Char e_ident[EI_NIDENT];
     Elf32_Half e_type;
@@ -64,6 +72,7 @@ typedef struct {
     Elf64_Half e_shnum;
     Elf64_Half e_shstrndx;
 } Elf64_Ehdr;
+/*@=matchfields@*/
 
 /* e_type */
 #define ET_EXEC                2
@@ -147,6 +156,7 @@ typedef struct {
     Elf32_Word sh_entsize;
 } Elf32_Shdr;
 
+/*@-matchfields@*/
 typedef struct {
     Elf64_Word sh_name;
     Elf64_Word sh_type;
@@ -159,6 +169,7 @@ typedef struct {
     Elf64_Off  sh_addralign;
     Elf64_Off  sh_entsize;
 } Elf64_Shdr;
+/*@=matchfields@*/
 
 /* Notes used in ET_CORE */
 #define NT_PRSTATUS    1
@@ -166,6 +177,8 @@ typedef struct {
 #define NT_PRPSINFO    3
 #define NT_TASKSTRUCT  4
 
+#define        NT_NETBSD_CORE_PROCINFO         1
+
 /* Note header in a PT_NOTE section */
 typedef struct elf_note {
     Elf32_Word n_namesz;       /* Name size */
@@ -186,4 +199,19 @@ typedef struct {
 #define        NT_PLATFORM     5
 #define        NT_AUXV         6
 
+/* Note types used in executables */
+/* NetBSD executables (name = "NetBSD") */
+#define NT_NETBSD_VERSION      1
+#define NT_NETBSD_EMULATION    2
+#define NT_FREEBSD_VERSION     1
+#define NT_OPENBSD_VERSION     1
+/* GNU executables (name = "GNU") */
+#define NT_GNU_VERSION         1
+
+/* GNU OS tags */
+#define GNU_OS_LINUX   0
+#define GNU_OS_HURD    1
+#define GNU_OS_SOLARIS 2
+/*@=redef@*/
+
 #endif
index bf7ddc6..5d1ef3b 100644 (file)
@@ -33,6 +33,7 @@ FILE_RCSID("@(#)Id: softmagic.c,v 1.51 2002/07/03 18:26:38 christos Exp ")
 
 /*@access fmagic @*/
 
+/*@-bounds@*/
 static int32_t
 fmagicSPrint(const fmagic fm, struct magic *m)
        /*@globals fileSystem @*/
@@ -46,7 +47,9 @@ fmagicSPrint(const fmagic fm, struct magic *m)
        case BYTE:
                v = signextend(m, p->b);
                fmagicPrintf(fm, m->desc, (unsigned char) v);
+/*@-sizeoftype@*/
                t = m->offset + sizeof(char);
+/*@=sizeoftype@*/
                break;
 
        case SHORT:
@@ -54,7 +57,9 @@ fmagicSPrint(const fmagic fm, struct magic *m)
        case LESHORT:
                v = signextend(m, p->h);
                fmagicPrintf(fm, m->desc, (unsigned short) v);
+/*@-sizeoftype@*/
                t = m->offset + sizeof(short);
+/*@=sizeoftype@*/
                break;
 
        case LONG:
@@ -62,7 +67,9 @@ fmagicSPrint(const fmagic fm, struct magic *m)
        case LELONG:
                v = signextend(m, p->l);
                fmagicPrintf(fm, m->desc, (uint32_t) v);
+/*@-sizeoftype@*/
                t = m->offset + sizeof(int32_t);
+/*@=sizeoftype@*/
                break;
 
        case STRING:
@@ -86,14 +93,18 @@ fmagicSPrint(const fmagic fm, struct magic *m)
        case BEDATE:
        case LEDATE:
                fmagicPrintf(fm, m->desc, fmttime(p->l, 1));
+/*@-sizeoftype@*/
                t = m->offset + sizeof(time_t);
+/*@=sizeoftype@*/
                break;
 
        case LDATE:
        case BELDATE:
        case LELDATE:
                fmagicPrintf(fm, m->desc, fmttime(p->l, 0));
+/*@-sizeoftype@*/
                t = m->offset + sizeof(time_t);
+/*@=sizeoftype@*/
                break;
        case REGEX:
                fmagicPrintf(fm, m->desc, p->s);
@@ -106,12 +117,14 @@ fmagicSPrint(const fmagic fm, struct magic *m)
        }
        return(t);
 }
+/*@=bounds@*/
 
 /*
  * Convert the byte order of the data we are looking at
  * While we're here, let's apply the mask operation
  * (unless you have a better idea)
  */
+/*@-bounds@*/
 static int
 fmagicSConvert(fmagic fm, struct magic *m)
        /*@globals fileSystem @*/
@@ -382,6 +395,7 @@ fmagicSConvert(fmagic fm, struct magic *m)
                return 0;
        }
 }
+/*@=bounds@*/
 
 
 static void
@@ -395,6 +409,7 @@ fmagicSDebug(int32_t offset, char *str, int len)
        (void) fputc('\n', stderr);
 }
 
+/*@-bounds@*/
 static int
 fmagicSGet(fmagic fm, struct magic *m)
        /*@globals fileSystem @*/
@@ -762,8 +777,10 @@ fmagicSGet(fmagic fm, struct magic *m)
                        break;
                }
 
-               if (offset + sizeof(*p) > nb)
+/*@-compmempass@*/
+               if (buf == NULL || offset + sizeof(*p) > nb)
                        return 0;
+/*@=compmempass@*/
 
                memcpy(p, buf + offset, sizeof(*p));
 
@@ -772,11 +789,15 @@ fmagicSGet(fmagic fm, struct magic *m)
                        mdump(m);
                }
        }
+/*@-compmempass@*/
        if (!fmagicSConvert(fm, m))
          return 0;
        return 1;
+/*@=compmempass@*/
 }
+/*@=bounds@*/
 
+/*@-bounds@*/
 static int
 fmagicSCheck(const fmagic fm, struct magic *m)
        /*@globals fileSystem @*/
@@ -874,7 +895,7 @@ fmagicSCheck(const fmagic fm, struct magic *m)
                        error(EXIT_FAILURE, 0, "regex error %d, (%s)\n", rc, errmsg);
                        /*@notreached@*/
                } else {
-                       rc = regexec(&rx, p->buf, 0, 0, 0);
+                       rc = regexec(&rx, p->buf, 0, NULL, 0);
                        return !rc;
                }
        }
@@ -961,6 +982,7 @@ fmagicSCheck(const fmagic fm, struct magic *m)
 
        return matched;
 }
+/*@=bounds@*/
 
 /*
  * Go through the whole list, stopping if you find a match.  Process all
@@ -989,6 +1011,7 @@ fmagicSCheck(const fmagic fm, struct magic *m)
  *     If a continuation matches, we bump the current continuation level
  *     so that higher-level continuations are processed.
  */
+/*@-bounds@*/
 static int
 fmagicSMatch(const fmagic fm)
        /*@globals fileSystem @*/
@@ -1093,6 +1116,7 @@ fmagicSMatch(const fmagic fm)
        }
        return ret;     /* This is hit if -k is set or there is no match */
 }
+/*@=bounds@*/
 
 /*
  * fmagicS - lookup one file in database 
@@ -1105,10 +1129,14 @@ fmagicS(fmagic fm)
 /*@-branchstate@*/
        if (fm->mlist != NULL)
        for (fm->ml = fm->mlist->next; fm->ml != fm->mlist; fm->ml = fm->ml->next) {
+/*@-compmempass@*/
                if (fmagicSMatch(fm))
                        return 1;
+/*@=compmempass@*/
        }
 /*@=branchstate@*/
 
+/*@-compmempass@*/
        return 0;
+/*@=compmempass@*/
 }
index d38e855..7ea2793 100644 (file)
@@ -1,5 +1,6 @@
 #ifndef        H_SYSTEM
 #define        H_SYSTEM
+/*@-redef@*/
 
 #ifndef __linux__
 #define _LARGEFILE_SOURCE
@@ -243,6 +244,7 @@ char * xstrdup (const char *str)
 
 /**
  */
+/*@-shadow@*/
 /*@unused@*/ /*@exits@*/ /*@only@*/
 static inline void * vmefail(/*@unused@*/ size_t nb)
        /*@globals fileSystem @*/
@@ -254,6 +256,7 @@ static inline void * vmefail(/*@unused@*/ size_t nb)
        return NULL;
 /*@=nullret@*/
 }
+/*@=shadow@*/
 
 #if HAVE_MCHECK_H
 #include <mcheck.h>
@@ -318,4 +321,6 @@ static inline const char *rcsid(const char *p) { \
 }
 #endif
 
+/*@=redef@*/
+
 #endif /* H_SYSTEM */
index d3afb19..c0dda6a 100644 (file)
@@ -50,7 +50,7 @@ union record {
 #define        CHKBLANKS       "        "      /* 8 blanks, no null */
 
 /* The magic field is filled with this if uname and gname are valid. */
-#define        TMAGIC          "ustar  "       /* 7 chars and a null */
+#define        TARMAGIC                "ustar  "       /* 7 chars and a null */
 
 #if 0
 /* The linkflag defines the type of file */