CVS patchset: 6025
CVS date: 2003/01/24 19:41:55
14 files changed:
--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
+strict # lclint level
# --- in progress
+strict # lclint level
# --- in progress
++bounds
+
+-fielduse
+-exportfcn
--formatconst # 1
--globstate # 3
--macroredef # 1 tar.h
--nullderef # 1
--nullpass # 5
--nullptrarith # 1
--redef # 1 tar.h
--sizeoftype # 14
# --- not-yet at strict level
-bitwisesigned # 86
# --- not-yet at strict level
-bitwisesigned # 86
lint:
$(LINT) $(DEFS) $(INCLUDES) $(file_SOURCES) $(libfmagic_la_SOURCES) $(pkginc_HEADERS) $(noinst_HEADERS)
lint:
$(LINT) $(DEFS) $(INCLUDES) $(file_SOURCES) $(libfmagic_la_SOURCES) $(pkginc_HEADERS) $(noinst_HEADERS)
+.PHONY: sources
+sources:
+ @echo $(libfmagic_la_SOURCES:%=file/%)
+
/*
* eatsize(): Eat the size spec from a number [eg. 10UL]
*/
/*
* eatsize(): Eat the size spec from a number [eg. 10UL]
*/
static void
eatsize(/*@out@*/ char **p)
/*@modifies *p @*/
static void
eatsize(/*@out@*/ char **p)
/*@modifies *p @*/
/* Single hex char to int; -1 if not a hex char. */
static int
/* Single hex char to int; -1 if not a hex char. */
static int
* Copy the converted version to "p", returning its length in *slen.
* Return updated scan pointer as function result.
*/
* 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 @*/
static char *
getstr(/*@returned@*/ char *s, char *p, int plen, /*@out@*/ int *slen)
/*@globals fileSystem @*/
*slen = p - origp;
return s;
}
*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.
*/
/*
* 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.
*/
static int
getvalue(struct magic *m, /*@out@*/ char **p)
/*@globals fileSystem @*/
static int
getvalue(struct magic *m, /*@out@*/ char **p)
/*@globals fileSystem @*/
/*
* parse one line from magic file, put into magic[index++] if valid
*/
/*
* parse one line from magic file, put into magic[index++] if valid
*/
static int
parse(/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp,
char *l, int action)
static int
parse(/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp,
char *l, int action)
++(*nmagicp); /* make room for next */
return 0;
}
++(*nmagicp); /* make room for next */
return 0;
}
/*
* Print a string containing C character escapes.
/*
* Print a string containing C character escapes.
static uint16_t
swap2(uint16_t sv)
/*@*/
static uint16_t
swap2(uint16_t sv)
/*@*/
d[1] = s[0];
return rv;
}
d[1] = s[0];
return rv;
}
static uint32_t
swap4(uint32_t sv)
/*@*/
static uint32_t
swap4(uint32_t sv)
/*@*/
d[3] = s[0];
return rv;
}
d[3] = s[0];
return rv;
}
/*
* byteswap a single magic entry
/*
* byteswap a single magic entry
/*
* Byteswap an mmap'ed file if needed
*/
/*
* Byteswap an mmap'ed file if needed
*/
static void
byteswap(/*@null@*/ struct magic *m, uint32_t nmagic)
/*@modifies m @*/
static void
byteswap(/*@null@*/ struct magic *m, uint32_t nmagic)
/*@modifies m @*/
for (i = 0; i < nmagic; i++)
bs1(&m[i]);
}
for (i = 0; i < nmagic; i++)
bs1(&m[i]);
}
* parse from a file
* const char *fn: name of magic file
*/
* parse from a file
* const char *fn: name of magic file
*/
static int
apprentice_file(fmagic fm, /*@out@*/ struct magic **magicp,
/*@out@*/ uint32_t *nmagicp, const char *fn, int action)
static int
apprentice_file(fmagic fm, /*@out@*/ struct magic **magicp,
/*@out@*/ uint32_t *nmagicp, const char *fn, int action)
/*
* handle an mmaped file.
*/
/*
* handle an mmaped file.
*/
static int
apprentice_compile(/*@unused@*/ const fmagic fm,
/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp,
static int
apprentice_compile(/*@unused@*/ const fmagic fm,
/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp,
(void)close(fd);
return 0;
}
(void)close(fd);
return 0;
}
/*
* handle a compiled file.
*/
/*
* handle a compiled file.
*/
static int
apprentice_map(/*@unused@*/ const fmagic fm,
/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp,
static int
apprentice_map(/*@unused@*/ const fmagic fm,
/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp,
(void)close(fd);
fd = -1;
ptr = (uint32_t *) *magicp;
(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",
if (*ptr != MAGICNO) {
if (swap4(*ptr) != MAGICNO) {
(void)fprintf(stderr, "%s: Bad magic in `%s'\n",
/*@=branchstate@*/
return -1;
}
/*@=branchstate@*/
return -1;
}
*
* Result is -1 if the field is invalid (all blank, or nonoctal).
*/
*
* Result is -1 if the field is invalid (all blank, or nonoctal).
*/
static int
from_oct(int digs, char *where)
/*@*/
static int
from_oct(int digs, char *where)
/*@*/
return -1; /* All blank field */
}
value = 0;
return -1; /* All blank field */
}
value = 0;
+/*@-shiftimplementation@*/
while (digs > 0 && isodigit(*where)) { /* Scan til nonoctal */
value = (value << 3) | (*where++ - '0');
--digs;
}
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;
}
if (digs > 0 && *where && !isspace((unsigned char)*where))
return -1; /* Ended on non-space/nul */
return value;
}
sum = 0;
p = header->charptr;
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.
/*
* We can't use unsigned char here because of old compilers,
* e.g. V7.
if (sum != recsum)
return 0; /* Not a tar archive */
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 */
return 2; /* Unix Standard tar archive */
return 1; /* Old fashioned tar archive */
I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I /* 0xfX */
};
I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I /* 0xfX */
};
static int
looks_ascii(const unsigned char *buf, int nb,
/*@out@*/ unichar *ubuf, /*@out@*/ int *ulen)
static int
looks_ascii(const unsigned char *buf, int nb,
/*@out@*/ unichar *ubuf, /*@out@*/ int *ulen)
static int
looks_latin1(const unsigned char *buf, int nb,
/*@out@*/ unichar *ubuf, /*@out@*/ int *ulen)
static int
looks_latin1(const unsigned char *buf, int nb,
/*@out@*/ unichar *ubuf, /*@out@*/ int *ulen)
static int
looks_extended(const unsigned char *buf, int nb,
/*@out@*/ unichar *ubuf, /*@out@*/ int *ulen)
static int
looks_extended(const unsigned char *buf, int nb,
/*@out@*/ unichar *ubuf, /*@out@*/ int *ulen)
static int
looks_utf8(const unsigned char *buf, int nb,
/*@out@*/ unichar *ubuf, /*@out@*/ int *ulen)
static int
looks_utf8(const unsigned char *buf, int nb,
/*@out@*/ unichar *ubuf, /*@out@*/ int *ulen)
done:
return gotone; /* don't claim it's UTF-8 if it's all 7-bit */
}
done:
return gotone; /* don't claim it's UTF-8 if it's all 7-bit */
}
static int
looks_unicode(const unsigned char *buf, int nb,
/*@out@*/ unichar *ubuf, /*@out@*/ int *ulen)
static int
looks_unicode(const unsigned char *buf, int nb,
/*@out@*/ unichar *ubuf, /*@out@*/ int *ulen)
/*
* Copy buf[0 ... nb-1] into out[], translating EBCDIC to ASCII.
*/
/*
* Copy buf[0 ... nb-1] into out[], translating EBCDIC to ASCII.
*/
static void
from_ebcdic(const unsigned char *buf, int nb, /*@out@*/ unsigned char *otp)
/*@modifies *otp @*/
static void
from_ebcdic(const unsigned char *buf, int nb, /*@out@*/ unsigned char *otp)
/*@modifies *otp @*/
otp[i] = ebcdic_to_ascii[buf[i]];
}
}
otp[i] = ebcdic_to_ascii[buf[i]];
}
}
static int
fmagicAMatch(const unsigned char *s, const unichar *us, int ulen)
/*@*/
static int
fmagicAMatch(const unsigned char *s, const unichar *us, int ulen)
/*@*/
/* int nb: size actually read */
/* int nb: size actually read */
/*
* compare the word thus isolated against the token list
*/
/*
* 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)) {
if (p->name == NULL)
/*@innerbreak@*/ break;
if (fmagicAMatch(p->name, ubuf + i, end - i)) {
#define FNAME (1 << 3)
#define FCOMMENT (1 << 4)
#define FNAME (1 << 3)
#define FCOMMENT (1 << 4)
static int
uncompressgzipped(const unsigned char *old,
/*@out@*/ unsigned char **newch, int n)
static int
uncompressgzipped(const unsigned char *old,
/*@out@*/ unsigned char **newch, int n)
z.zfree = NULL;
z.opaque = NULL;
z.zfree = NULL;
z.opaque = NULL;
/*@-type@*/
rc = inflateInit2(&z, -15);
/*@=type@*/
/*@-type@*/
rc = inflateInit2(&z, -15);
/*@=type@*/
if (rc != Z_OK) {
(void) fprintf(stderr,"%s: zlib: %s\n", __progname, z.msg);
return 0;
if (rc != Z_OK) {
(void) fprintf(stderr,"%s: zlib: %s\n", __progname, z.msg);
return 0;
static int
uncompressbuf(int method, const unsigned char *old,
/*@out@*/ unsigned char **newch, int n)
static int
uncompressbuf(int method, const unsigned char *old,
/*@out@*/ unsigned char **newch, int n)
/*@notreached@*/
return 0;
}
/*@notreached@*/
return 0;
}
int i;
for (i = 0; i < ncompr; i++) {
int i;
for (i = 0; i < ncompr; i++) {
if (nb < compr[i].maglen)
continue;
if (nb < compr[i].maglen)
continue;
if (memcmp(buf, compr[i].magic, compr[i].maglen) == 0 &&
(newsize = uncompressbuf(i, buf, &newbuf, nb)) != 0) {
fm->buf = newbuf;
if (memcmp(buf, compr[i].magic, compr[i].maglen) == 0 &&
(newsize = uncompressbuf(i, buf, &newbuf, nb)) != 0) {
fm->buf = newbuf;
/*
* unwrap -- read a file of filenames, do each one.
*/
/*
* unwrap -- read a file of filenames, do each one.
*/
static void
unwrap(fmagic fm, char *fn)
/*@globals fileSystem, internalState @*/
static void
unwrap(fmagic fm, char *fn)
/*@globals fileSystem, internalState @*/
- 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';
buf[strlen(buf)-1] = '\0';
fm->obp = fm->obuf;
*fm->obp = '\0';
/*
* main - parse arguments and handle options
*/
/*
* main - parse arguments and handle options
*/
int
main(int argc, char **argv)
/*@globals global_fmagic, nobuffer,
int
main(int argc, char **argv)
/*@globals global_fmagic, nobuffer,
+/*@-nullpass@*/ /* FIX: fm->magicfile may be null */
ret = fmagicSetup(fm, fm->magicfile, action);
ret = fmagicSetup(fm, fm->magicfile, action);
if (action)
exit(ret);
app = 1;
if (action)
exit(ret);
app = 1;
#ifndef __file_h__
#define __file_h__
#ifndef __file_h__
#define __file_h__
#ifndef HOWMANY
# define HOWMANY 65536 /* how much of the file to look at */
#endif
#ifndef HOWMANY
# define HOWMANY 65536 /* how much of the file to look at */
#endif
dv_unit(st->st_rdev),
dv_subunit(st->st_rdev));
# else
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));
fmagicPrintf(fm, "character special (%ld/%ld)",
(long) major(st->st_rdev), (long) minor(st->st_rdev));
+/*@=shiftimplementation@*/
# endif
#else
fmagicPrintf(fm, "character special");
# endif
#else
fmagicPrintf(fm, "character special");
dv_unit(st->st_rdev),
dv_subunit(st->st_rdev));
# else
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));
fmagicPrintf(fm, "block special (%ld/%ld)",
(long) major(st->st_rdev), (long) minor(st->st_rdev));
+/*@=shiftimplementation@*/
# endif
#else
fmagicPrintf(fm, "block special");
# endif
#else
fmagicPrintf(fm, "block special");
int
fmagicF(fmagic fm, int zfl)
int
fmagicF(fmagic fm, int zfl)
/*
* fmagicProcess - process input file
*/
/*
* fmagicProcess - process input file
*/
int
fmagicProcess(fmagic fm, const char *fn, int wid)
{
int
fmagicProcess(fmagic fm, const char *fn, int wid)
{
fm->nb = 0;
return ret;
}
fm->nb = 0;
return ret;
}
static const char optyp[] = { '@', '&', '|', '^', '+', '-',
'*', '/', '%' };
(void) fputc('[', stderr);
static const char optyp[] = { '@', '&', '|', '^', '+', '-',
'*', '/', '%' };
(void) fputc('[', stderr);
(void) fprintf(stderr, ">>>>>>>> %d" + 8 - (m->cont_level & 7),
m->offset);
(void) fprintf(stderr, ">>>>>>>> %d" + 8 - (m->cont_level & 7),
m->offset);
if (m->flag & INDIR) {
(void) fprintf(stderr, "(%s,",
if (m->flag & INDIR) {
(void) fprintf(stderr, "(%s,",
(void) vfprintf(stderr, f, va);
va_end(va);
(void) fputc('\n', stderr);
(void) vfprintf(stderr, f, va);
va_end(va);
(void) fputc('\n', stderr);
+/*@-globstate@*/ /* FIX: __progname might be null */
+ return;
+/*@=globstate@*/
rc = vsnprintf(fm->obp, fm->nob, f, va);
rc = vsnprintf(fm->obp, fm->nob, f, va);
va_end(va);
fm->obuf[sizeof(fm->obuf)-1] = '\0';
va_end(va);
fm->obuf[sizeof(fm->obuf)-1] = '\0';
char *
fmttime(long v, int local)
{
char *
fmttime(long v, int local)
{
+ char *pp = "???";
+ char *rt;
time_t t = (time_t)v;
struct tm *tm;
time_t t = (time_t)v;
struct tm *tm;
if (daylight)
t += 3600;
tm = gmtime(&t);
if (daylight)
t += 3600;
tm = gmtime(&t);
+ if (tm != NULL)
+ pp = asctime(tm);
static uint16_t
getu16(const fmagic fm, uint16_t value)
/*@*/
static uint16_t
getu16(const fmagic fm, uint16_t value)
/*@*/
#define sh_addr (fm->cls == ELFCLASS32 \
? (void *) &sh32 \
#define sh_addr (fm->cls == ELFCLASS32 \
? (void *) &sh32 \
? prpsoffsets32[i] \
: prpsoffsets64[i])
? prpsoffsets32[i] \
: prpsoffsets64[i])
static void
doshn(fmagic fm, off_t off, int num, size_t size)
/*@globals fileSystem @*/
static void
doshn(fmagic fm, off_t off, int num, size_t size)
/*@globals fileSystem @*/
}
fmagicPrintf(fm, ", stripped");
}
}
fmagicPrintf(fm, ", stripped");
}
/*
* 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.
*/
/*
* 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.
*/
static void
dophn_exec(fmagic fm, off_t off, int num, size_t size)
/*@globals fileSystem @*/
static void
dophn_exec(fmagic fm, off_t off, int num, size_t size)
/*@globals fileSystem @*/
/*
* We're out of note headers.
*/
/*
* We're out of note headers.
*/
+ /*@innerbreak@*/ break;
}
if (offset + nh_descsz >= bufsize)
}
if (offset + nh_descsz >= bufsize)
}
fmagicPrintf(fm, ", %s linked%s", linking_style, shared_libraries);
}
}
fmagicPrintf(fm, ", %s linked%s", linking_style, shared_libraries);
}
#ifdef ELFCORE
/*@unchecked@*/ /*@observer@*/
#ifdef ELFCORE
/*@unchecked@*/ /*@observer@*/
static void
dophn_core(fmagic fm, off_t off, int num, size_t size)
/*@globals fileSystem @*/
static void
dophn_core(fmagic fm, off_t off, int num, size_t size)
/*@globals fileSystem @*/
void
fmagicE(fmagic fm)
{
void
fmagicE(fmagic fm)
{
union {
int32_t l;
char c[sizeof (int32_t)];
} u;
union {
int32_t l;
char c[sizeof (int32_t)];
} u;
/*
* If we can't seek, it must be a pipe, socket or fifo.
/*
* If we can't seek, it must be a pipe, socket or fifo.
if (fm->cls == ELFCLASS32) {
Elf32_Ehdr elfhdr;
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);
return;
u.l = 1;
(void) memcpy(&elfhdr, fm->buf, sizeof elfhdr);
fm->swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[EI_DATA];
fm->swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[EI_DATA];
if (getu16(fm, elfhdr.e_type) == ET_CORE)
#ifdef ELFCORE
if (getu16(fm, elfhdr.e_type) == ET_CORE)
#ifdef ELFCORE
if (fm->cls == ELFCLASS64) {
Elf64_Ehdr elfhdr;
if (fm->cls == ELFCLASS64) {
Elf64_Ehdr elfhdr;
- if (fm->nb <= sizeof (Elf64_Ehdr))
+ if (fm->nb <= sizeof (elfhdr))
u.l = 1;
(void) memcpy(&elfhdr, fm->buf, sizeof elfhdr);
u.l = 1;
(void) memcpy(&elfhdr, fm->buf, sizeof elfhdr);
fm->swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[EI_DATA];
fm->swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[EI_DATA];
if (getu16(fm, elfhdr.e_type) == ET_CORE)
#ifdef ELFCORE
if (getu16(fm, elfhdr.e_type) == ET_CORE)
#ifdef ELFCORE
+/* $NetBSD: readelf.h,v 1.9 2002/05/18 07:00:47 pooka Exp $ */
+/*@-redef@*/
+
- * @(#)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.
*
* Provide elf data structures for non-elf machines, allowing file
* non-elf hosts to determine if an elf binary is stripped.
#ifndef __fake_elf_h__
#define __fake_elf_h__
#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;
typedef uint32_t Elf32_Addr;
typedef uint32_t Elf32_Off;
typedef uint16_t Elf32_Half;
typedef struct {
Elf32_Char e_ident[EI_NIDENT];
Elf32_Half e_type;
typedef struct {
Elf32_Char e_ident[EI_NIDENT];
Elf32_Half e_type;
Elf64_Half e_shnum;
Elf64_Half e_shstrndx;
} Elf64_Ehdr;
Elf64_Half e_shnum;
Elf64_Half e_shstrndx;
} Elf64_Ehdr;
/* e_type */
#define ET_EXEC 2
/* e_type */
#define ET_EXEC 2
Elf32_Word sh_entsize;
} Elf32_Shdr;
Elf32_Word sh_entsize;
} Elf32_Shdr;
typedef struct {
Elf64_Word sh_name;
Elf64_Word sh_type;
typedef struct {
Elf64_Word sh_name;
Elf64_Word sh_type;
Elf64_Off sh_addralign;
Elf64_Off sh_entsize;
} Elf64_Shdr;
Elf64_Off sh_addralign;
Elf64_Off sh_entsize;
} Elf64_Shdr;
/* Notes used in ET_CORE */
#define NT_PRSTATUS 1
/* Notes used in ET_CORE */
#define NT_PRSTATUS 1
#define NT_PRPSINFO 3
#define NT_TASKSTRUCT 4
#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 */
/* Note header in a PT_NOTE section */
typedef struct elf_note {
Elf32_Word n_namesz; /* Name size */
#define NT_PLATFORM 5
#define NT_AUXV 6
#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@*/
+
static int32_t
fmagicSPrint(const fmagic fm, struct magic *m)
/*@globals fileSystem @*/
static int32_t
fmagicSPrint(const fmagic fm, struct magic *m)
/*@globals fileSystem @*/
case BYTE:
v = signextend(m, p->b);
fmagicPrintf(fm, m->desc, (unsigned char) v);
case BYTE:
v = signextend(m, p->b);
fmagicPrintf(fm, m->desc, (unsigned char) v);
t = m->offset + sizeof(char);
t = m->offset + sizeof(char);
case LESHORT:
v = signextend(m, p->h);
fmagicPrintf(fm, m->desc, (unsigned short) v);
case LESHORT:
v = signextend(m, p->h);
fmagicPrintf(fm, m->desc, (unsigned short) v);
t = m->offset + sizeof(short);
t = m->offset + sizeof(short);
case LELONG:
v = signextend(m, p->l);
fmagicPrintf(fm, m->desc, (uint32_t) v);
case LELONG:
v = signextend(m, p->l);
fmagicPrintf(fm, m->desc, (uint32_t) v);
t = m->offset + sizeof(int32_t);
t = m->offset + sizeof(int32_t);
case BEDATE:
case LEDATE:
fmagicPrintf(fm, m->desc, fmttime(p->l, 1));
case BEDATE:
case LEDATE:
fmagicPrintf(fm, m->desc, fmttime(p->l, 1));
t = m->offset + sizeof(time_t);
t = m->offset + sizeof(time_t);
break;
case LDATE:
case BELDATE:
case LELDATE:
fmagicPrintf(fm, m->desc, fmttime(p->l, 0));
break;
case LDATE:
case BELDATE:
case LELDATE:
fmagicPrintf(fm, m->desc, fmttime(p->l, 0));
t = m->offset + sizeof(time_t);
t = m->offset + sizeof(time_t);
break;
case REGEX:
fmagicPrintf(fm, m->desc, p->s);
break;
case REGEX:
fmagicPrintf(fm, m->desc, p->s);
/*
* 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)
*/
/*
* 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)
*/
static int
fmagicSConvert(fmagic fm, struct magic *m)
/*@globals fileSystem @*/
static int
fmagicSConvert(fmagic fm, struct magic *m)
/*@globals fileSystem @*/
(void) fputc('\n', stderr);
}
(void) fputc('\n', stderr);
}
static int
fmagicSGet(fmagic fm, struct magic *m)
/*@globals fileSystem @*/
static int
fmagicSGet(fmagic fm, struct magic *m)
/*@globals fileSystem @*/
- if (offset + sizeof(*p) > nb)
+/*@-compmempass@*/
+ if (buf == NULL || offset + sizeof(*p) > nb)
memcpy(p, buf + offset, sizeof(*p));
memcpy(p, buf + offset, sizeof(*p));
if (!fmagicSConvert(fm, m))
return 0;
return 1;
if (!fmagicSConvert(fm, m))
return 0;
return 1;
static int
fmagicSCheck(const fmagic fm, struct magic *m)
/*@globals fileSystem @*/
static int
fmagicSCheck(const fmagic fm, struct magic *m)
/*@globals fileSystem @*/
error(EXIT_FAILURE, 0, "regex error %d, (%s)\n", rc, errmsg);
/*@notreached@*/
} else {
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);
/*
* Go through the whole list, stopping if you find a match. Process all
/*
* Go through the whole list, stopping if you find a match. Process all
* If a continuation matches, we bump the current continuation level
* so that higher-level continuations are processed.
*/
* If a continuation matches, we bump the current continuation level
* so that higher-level continuations are processed.
*/
static int
fmagicSMatch(const fmagic fm)
/*@globals fileSystem @*/
static int
fmagicSMatch(const fmagic fm)
/*@globals fileSystem @*/
}
return ret; /* This is hit if -k is set or there is no match */
}
}
return ret; /* This is hit if -k is set or there is no match */
}
/*
* fmagicS - lookup one file in database
/*
* fmagicS - lookup one file in database
/*@-branchstate@*/
if (fm->mlist != NULL)
for (fm->ml = fm->mlist->next; fm->ml != fm->mlist; fm->ml = fm->ml->next) {
/*@-branchstate@*/
if (fm->mlist != NULL)
for (fm->ml = fm->mlist->next; fm->ml != fm->mlist; fm->ml = fm->ml->next) {
if (fmagicSMatch(fm))
return 1;
if (fmagicSMatch(fm))
return 1;
#ifndef H_SYSTEM
#define H_SYSTEM
#ifndef H_SYSTEM
#define H_SYSTEM
#ifndef __linux__
#define _LARGEFILE_SOURCE
#ifndef __linux__
#define _LARGEFILE_SOURCE
/*@unused@*/ /*@exits@*/ /*@only@*/
static inline void * vmefail(/*@unused@*/ size_t nb)
/*@globals fileSystem @*/
/*@unused@*/ /*@exits@*/ /*@only@*/
static inline void * vmefail(/*@unused@*/ size_t nb)
/*@globals fileSystem @*/
return NULL;
/*@=nullret@*/
}
return NULL;
/*@=nullret@*/
}
#if HAVE_MCHECK_H
#include <mcheck.h>
#if HAVE_MCHECK_H
#include <mcheck.h>
#define CHKBLANKS " " /* 8 blanks, no null */
/* The magic field is filled with this if uname and gname are valid. */
#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 */
#if 0
/* The linkflag defines the type of file */