merge conflicts

This commit is contained in:
christos 2012-02-22 17:53:48 +00:00
parent 9f333c4c84
commit 046a38dd85
20 changed files with 264 additions and 312 deletions

View File

@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.64 for file 5.09.
# Generated by GNU Autoconf 2.68 for file 5.11.
#
# Report bugs to <christos@astron.com>.
#
@ -698,8 +698,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='file'
PACKAGE_TARNAME='file'
PACKAGE_VERSION='5.09'
PACKAGE_STRING='file 5.09'
PACKAGE_VERSION='5.11'
PACKAGE_STRING='file 5.11'
PACKAGE_BUGREPORT='christos@astron.com'
PACKAGE_URL=''
@ -1431,7 +1431,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures file 5.09 to adapt to many kinds of systems.
\`configure' configures file 5.11 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@ -1501,7 +1501,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of file 5.09:";;
short | recursive ) echo "Configuration of file 5.11:";;
esac
cat <<\_ACEOF
@ -1609,8 +1609,8 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
file configure 5.09
generated by GNU Autoconf 2.64
file configure 5.11
generated by GNU Autoconf 2.68
Copyright (C) 2009 Free Software Foundation, Inc.
This configure script is free software; the Free Software Foundation
@ -2308,8 +2308,8 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by file $as_me 5.09, which was
generated by GNU Autoconf 2.64. Invocation command line was
It was created by file $as_me 5.11, which was
generated by GNU Autoconf 2.68. Invocation command line was
$ $0 $@
@ -3116,7 +3116,7 @@ fi
# Define the identity of the package.
PACKAGE='file'
VERSION='5.09'
VERSION='5.11'
cat >>confdefs.h <<_ACEOF
@ -13477,8 +13477,8 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by file $as_me 5.09, which was
generated by GNU Autoconf 2.64. Invocation command line was
This file was extended by file $as_me 5.11, which was
generated by GNU Autoconf 2.68. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
CONFIG_HEADERS = $CONFIG_HEADERS
@ -13541,9 +13541,9 @@ Report bugs to <christos@astron.com>."
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_version="\\
file config.status 5.09
configured by $0, generated by GNU Autoconf 2.64,
with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
file config.status 5.11
configured by $0, generated by GNU Autoconf 2.68,
with options \\"\$ac_cs_config\\"
Copyright (C) 2009 Free Software Foundation, Inc.
This config.status script is free software; the Free Software Foundation

View File

@ -1,5 +1,5 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT(file, 5.09, christos@astron.com)
AC_INIT(file, 5.11, christos@astron.com)
AM_INIT_AUTOMAKE()
AM_MAINTAINER_MODE(disable)
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])

View File

@ -1,7 +1,7 @@
.\" $NetBSD: file.1,v 1.8 2011/09/16 21:06:25 christos Exp $
.\" $NetBSD: file.1,v 1.9 2012/02/22 17:53:50 christos Exp $
.\"
.\" $File: file.man,v 1.96 2011/07/12 11:23:38 rrt Exp $
.Dd April 20, 2011
.\" $File: file.man,v 1.98 2011/12/08 12:12:46 rrt Exp $
.Dd October 17, 2011
.Dt FILE 1
.Os
.Sh NAME
@ -26,7 +26,7 @@
.Nm
.Op Fl Fl help
.Sh DESCRIPTION
This manual page documents version 5.09 of the
This manual page documents version 5.11 of the
.Nm
command.
.Pp
@ -194,7 +194,7 @@ option).
.It encoding
Different text encodings for soft magic tests.
.It tokens
Looks for known tokens inside text files.
Ignored for backwards compatibility.
.It cdf
Prints details of Compound Document Files.
.It compress
@ -222,6 +222,19 @@ or at least one filename argument must be present;
to test the standard input, use
.Sq -
as a filename argument.
Please note that
.Ar namefile
is unwrapped and the enclosed filenames are processed when this option is
encountered and before any further options processing is done.
This allows one to process multiple lists of files with different command line
arguments on the same
.Nm
invocation.
Thus if you want to set the delimiter, you need to do it before you specify
the list of files, like:
.Dq Fl F Ar @ Fl f Ar namefile ,
instead of:
.Dq Fl f Ar namefile Fl F Ar @ .
.It Fl h , Fl Fl no-dereference
option causes symlinks not to be followed
(on systems that support symbolic links).

View File

@ -1,6 +1,6 @@
.\" $NetBSD: libmagic.3,v 1.9 2011/11/10 13:41:00 christos Exp $
.\" $NetBSD: libmagic.3,v 1.10 2012/02/22 17:53:50 christos Exp $
.\"
.\" $File: libmagic.man,v 1.24 2011/05/13 22:11:44 christos Exp $
.\" $File: libmagic.man,v 1.26 2011/12/19 17:49:31 christos Exp $
.\"
.\" Copyright (c) Christos Zoulas 2003.
.\" All Rights Reserved.
@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd January 14, 2011
.Dd December 19, 2011
.Dt LIBMAGIC 3
.Os
.Sh NAME
@ -66,6 +66,8 @@
.Ft int
.Fn magic_compile "magic_t cookie" "const char *filename"
.Ft int
.Fn magic_list "magic_t cookie" "const char *filename"
.Ft int
.Fn magic_load "magic_t cookie" "const char *filename"
.Sh DESCRIPTION
These functions
@ -221,6 +223,17 @@ of each file argument with
appended to it.
.Pp
The
.Fn magic_list
function dumps all magic entries in a human readable format,
dumping first the entries that are matched against binary files and then the
ones that match text files.
It takes and optional
.Fa filename
argument which is a colon separated list of database files, or
.Dv NULL
for the default database.
.Pp
The
.Fn magic_load
function must be used to load the the colon
separated list of database files passed in as
@ -246,15 +259,17 @@ It will set errno to
.Er EINVAL
if an unsupported value for flags was given.
The
.Fn magic_list ,
.Fn magic_load ,
.Fn magic_compile ,
and
.Fn magic_check
functions return 0 on success and \-1 on failure.
The
.Fn magic_file ,
.Fn magic_buffer ,
.Fn magic_getpath ,
and
.Fn magic_buffer
.Fn magic_file ,
functions return a string on success and
.Dv NULL
on failure.

View File

@ -1,6 +1,6 @@
.\" $NetBSD: magic.5,v 1.6 2011/09/16 21:06:25 christos Exp $
.\" $NetBSD: magic.5,v 1.7 2012/02/22 17:53:50 christos Exp $
.\"
.\" $File: magic.man,v 1.69 2011/05/13 22:11:44 christos Exp $
.\" $File: magic.man,v 1.71 2011/12/07 11:58:24 rrt Exp $
.Dd April 20, 2011
.Dt MAGIC 5
.Os
@ -12,7 +12,7 @@
This manual page documents the format of the magic file as
used by the
.Xr file 1
command, version 5.09.
command, version 5.11.
The
.Xr file 1
command identifies the type of a file using,
@ -65,16 +65,16 @@ consecutive blanks, the target needs at least
consecutive blanks to match.
The
.Dq w
flag treats every blank in the target as an optional blank.
flag treats every blank in the magic as an optional blank.
The
.Dq c
flag, specifies case insensitive matching: lower case
flag specifies case insensitive matching: lower case
characters in the magic match both lower and upper case characters in the
target, whereas upper case characters in the magic only match upper case
characters in the target.
The
.Dq C
flag, specifies case insensitive matching: upper case
flag specifies case insensitive matching: upper case
characters in the magic match both lower and upper case characters in the
target, whereas lower case characters in the magic only match upper case
characters in the target.
@ -84,9 +84,9 @@ and
.Dq C .
The
.Dq t
flag, forces the test to be done for text files, while the
flag forces the test to be done for text files, while the
.Dq b
flag, forces the test to be done for binary files.
flag forces the test to be done for binary files.
.It Dv pstring
A Pascal-style string where the first byte/short/int is interpreted as the an
unsigned length.

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# $NetBSD: install-sh,v 1.4 2011/09/25 18:18:44 christos Exp $
# NetBSD: install-sh.in,v 1.5 2010/10/08 19:57:05 tez Exp
# This script now also installs multiple files, but might choke on installing
# multiple files with spaces in the file names.
#

View File

@ -1,5 +1,5 @@
#
# $File: Makefile.am,v 1.73 2011/09/08 21:58:42 christos Exp $
# $File: Makefile.am,v 1.78 2012/01/27 01:41:26 christos Exp $
#
MAGIC_FRAGMENT_BASE = magdir
MAGIC_DIR = $(top_srcdir)/magic
@ -22,6 +22,7 @@ $(MAGIC_FRAGMENT_DIR)/apl \
$(MAGIC_FRAGMENT_DIR)/apple \
$(MAGIC_FRAGMENT_DIR)/applix \
$(MAGIC_FRAGMENT_DIR)/archive \
$(MAGIC_FRAGMENT_DIR)/assembler \
$(MAGIC_FRAGMENT_DIR)/asterix \
$(MAGIC_FRAGMENT_DIR)/att3b \
$(MAGIC_FRAGMENT_DIR)/audio \
@ -52,6 +53,7 @@ $(MAGIC_FRAGMENT_DIR)/console \
$(MAGIC_FRAGMENT_DIR)/convex \
$(MAGIC_FRAGMENT_DIR)/cracklib \
$(MAGIC_FRAGMENT_DIR)/ctags \
$(MAGIC_FRAGMENT_DIR)/cups \
$(MAGIC_FRAGMENT_DIR)/dact \
$(MAGIC_FRAGMENT_DIR)/database \
$(MAGIC_FRAGMENT_DIR)/diamond \
@ -88,6 +90,7 @@ $(MAGIC_FRAGMENT_DIR)/gnumeric \
$(MAGIC_FRAGMENT_DIR)/grace \
$(MAGIC_FRAGMENT_DIR)/graphviz \
$(MAGIC_FRAGMENT_DIR)/gringotts \
$(MAGIC_FRAGMENT_DIR)/guile \
$(MAGIC_FRAGMENT_DIR)/hitachi-sh \
$(MAGIC_FRAGMENT_DIR)/hp \
$(MAGIC_FRAGMENT_DIR)/human68k \
@ -114,10 +117,12 @@ $(MAGIC_FRAGMENT_DIR)/lisp \
$(MAGIC_FRAGMENT_DIR)/llvm \
$(MAGIC_FRAGMENT_DIR)/lua \
$(MAGIC_FRAGMENT_DIR)/luks \
$(MAGIC_FRAGMENT_DIR)/m4 \
$(MAGIC_FRAGMENT_DIR)/mach \
$(MAGIC_FRAGMENT_DIR)/macintosh \
$(MAGIC_FRAGMENT_DIR)/magic \
$(MAGIC_FRAGMENT_DIR)/mail.news \
$(MAGIC_FRAGMENT_DIR)/make \
$(MAGIC_FRAGMENT_DIR)/maple \
$(MAGIC_FRAGMENT_DIR)/marc21 \
$(MAGIC_FRAGMENT_DIR)/mathcad \
@ -140,6 +145,7 @@ $(MAGIC_FRAGMENT_DIR)/msdos \
$(MAGIC_FRAGMENT_DIR)/msooxml \
$(MAGIC_FRAGMENT_DIR)/msvc \
$(MAGIC_FRAGMENT_DIR)/mup \
$(MAGIC_FRAGMENT_DIR)/music \
$(MAGIC_FRAGMENT_DIR)/natinst \
$(MAGIC_FRAGMENT_DIR)/ncr \
$(MAGIC_FRAGMENT_DIR)/netbsd \
@ -159,6 +165,7 @@ $(MAGIC_FRAGMENT_DIR)/osf1 \
$(MAGIC_FRAGMENT_DIR)/palm \
$(MAGIC_FRAGMENT_DIR)/parix \
$(MAGIC_FRAGMENT_DIR)/parrot \
$(MAGIC_FRAGMENT_DIR)/pascal \
$(MAGIC_FRAGMENT_DIR)/pbm \
$(MAGIC_FRAGMENT_DIR)/pdf \
$(MAGIC_FRAGMENT_DIR)/pdp \
@ -238,6 +245,7 @@ $(MAGIC_FRAGMENT_DIR)/xenix \
$(MAGIC_FRAGMENT_DIR)/xilinx \
$(MAGIC_FRAGMENT_DIR)/xo65 \
$(MAGIC_FRAGMENT_DIR)/xwindows \
$(MAGIC_FRAGMENT_DIR)/zfs \
$(MAGIC_FRAGMENT_DIR)/zilog \
$(MAGIC_FRAGMENT_DIR)/zyxel

View File

@ -197,7 +197,7 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
#
# $File: Makefile.am,v 1.73 2011/09/08 21:58:42 christos Exp $
# $File: Makefile.am,v 1.78 2012/01/27 01:41:26 christos Exp $
#
MAGIC_FRAGMENT_BASE = magdir
MAGIC_DIR = $(top_srcdir)/magic
@ -218,6 +218,7 @@ $(MAGIC_FRAGMENT_DIR)/apl \
$(MAGIC_FRAGMENT_DIR)/apple \
$(MAGIC_FRAGMENT_DIR)/applix \
$(MAGIC_FRAGMENT_DIR)/archive \
$(MAGIC_FRAGMENT_DIR)/assembler \
$(MAGIC_FRAGMENT_DIR)/asterix \
$(MAGIC_FRAGMENT_DIR)/att3b \
$(MAGIC_FRAGMENT_DIR)/audio \
@ -248,6 +249,7 @@ $(MAGIC_FRAGMENT_DIR)/console \
$(MAGIC_FRAGMENT_DIR)/convex \
$(MAGIC_FRAGMENT_DIR)/cracklib \
$(MAGIC_FRAGMENT_DIR)/ctags \
$(MAGIC_FRAGMENT_DIR)/cups \
$(MAGIC_FRAGMENT_DIR)/dact \
$(MAGIC_FRAGMENT_DIR)/database \
$(MAGIC_FRAGMENT_DIR)/diamond \
@ -284,6 +286,7 @@ $(MAGIC_FRAGMENT_DIR)/gnumeric \
$(MAGIC_FRAGMENT_DIR)/grace \
$(MAGIC_FRAGMENT_DIR)/graphviz \
$(MAGIC_FRAGMENT_DIR)/gringotts \
$(MAGIC_FRAGMENT_DIR)/guile \
$(MAGIC_FRAGMENT_DIR)/hitachi-sh \
$(MAGIC_FRAGMENT_DIR)/hp \
$(MAGIC_FRAGMENT_DIR)/human68k \
@ -310,10 +313,12 @@ $(MAGIC_FRAGMENT_DIR)/lisp \
$(MAGIC_FRAGMENT_DIR)/llvm \
$(MAGIC_FRAGMENT_DIR)/lua \
$(MAGIC_FRAGMENT_DIR)/luks \
$(MAGIC_FRAGMENT_DIR)/m4 \
$(MAGIC_FRAGMENT_DIR)/mach \
$(MAGIC_FRAGMENT_DIR)/macintosh \
$(MAGIC_FRAGMENT_DIR)/magic \
$(MAGIC_FRAGMENT_DIR)/mail.news \
$(MAGIC_FRAGMENT_DIR)/make \
$(MAGIC_FRAGMENT_DIR)/maple \
$(MAGIC_FRAGMENT_DIR)/marc21 \
$(MAGIC_FRAGMENT_DIR)/mathcad \
@ -336,6 +341,7 @@ $(MAGIC_FRAGMENT_DIR)/msdos \
$(MAGIC_FRAGMENT_DIR)/msooxml \
$(MAGIC_FRAGMENT_DIR)/msvc \
$(MAGIC_FRAGMENT_DIR)/mup \
$(MAGIC_FRAGMENT_DIR)/music \
$(MAGIC_FRAGMENT_DIR)/natinst \
$(MAGIC_FRAGMENT_DIR)/ncr \
$(MAGIC_FRAGMENT_DIR)/netbsd \
@ -355,6 +361,7 @@ $(MAGIC_FRAGMENT_DIR)/osf1 \
$(MAGIC_FRAGMENT_DIR)/palm \
$(MAGIC_FRAGMENT_DIR)/parix \
$(MAGIC_FRAGMENT_DIR)/parrot \
$(MAGIC_FRAGMENT_DIR)/pascal \
$(MAGIC_FRAGMENT_DIR)/pbm \
$(MAGIC_FRAGMENT_DIR)/pdf \
$(MAGIC_FRAGMENT_DIR)/pdp \
@ -434,6 +441,7 @@ $(MAGIC_FRAGMENT_DIR)/xenix \
$(MAGIC_FRAGMENT_DIR)/xilinx \
$(MAGIC_FRAGMENT_DIR)/xo65 \
$(MAGIC_FRAGMENT_DIR)/xwindows \
$(MAGIC_FRAGMENT_DIR)/zfs \
$(MAGIC_FRAGMENT_DIR)/zilog \
$(MAGIC_FRAGMENT_DIR)/zyxel

View File

@ -1,5 +1,5 @@
#------------------------------------------------------------------------------
# $File: archive,v 1.68 2011/09/07 15:47:51 christos Exp $
# $File: archive,v 1.70 2011/10/26 15:44:47 christos Exp $
# archive: file(1) magic for archive formats (see also "msdos" for self-
# extracting compressed archives)
#
@ -12,6 +12,11 @@
257 string ustar\040\040\0 GNU tar archive
!:mime application/x-tar # encoding: gnu
# Incremental snapshot gnu-tar format from:
# http://www.gnu.org/software/tar/manual/html_node/Snapshot-Files.html
0 string GNU\ tar- GNU tar incremental snapshot data
>&0 regex [0-9]\.[0-9]+-[0-9]+ version %s
# cpio archives
#
# Yes, the top two "cpio archive" formats *are* supposed to just be "short".

View File

@ -248,7 +248,7 @@ AM_CPPFLAGS = -DMAGIC='"$(MAGIC)"'
AM_CFLAGS = @WARNINGS@
libmagic_la_SOURCES = magic.c apprentice.c softmagic.c ascmagic.c \
encoding.c compress.c is_tar.c readelf.c print.c fsmagic.c \
funcs.c file.h names.h readelf.h tar.h apptype.c \
funcs.c file.h readelf.h tar.h apptype.c \
file_opts.h elfclass.h mygetopt.h cdf.c cdf_time.c readcdf.c cdf.h
libmagic_la_LDFLAGS = -no-undefined -version-info 1:0:0

View File

@ -1,4 +1,4 @@
/* $NetBSD: apprentice.c,v 1.5 2011/09/16 21:06:26 christos Exp $ */
/* $NetBSD: apprentice.c,v 1.6 2012/02/22 17:53:51 christos Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -35,9 +35,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: apprentice.c,v 1.170 2011/06/10 09:23:28 christos Exp $")
FILE_RCSID("@(#)$File: apprentice.c,v 1.173 2011/12/08 12:38:24 rrt Exp $")
#else
__RCSID("$NetBSD: apprentice.c,v 1.5 2011/09/16 21:06:26 christos Exp $");
__RCSID("$NetBSD: apprentice.c,v 1.6 2012/02/22 17:53:51 christos Exp $");
#endif
#endif /* lint */
@ -742,8 +742,7 @@ load_1(struct magic_set *ms, int action, const char *fn, int *errs,
break;
}
}
if (line)
free(line);
free(line);
(void)fclose(f);
}
@ -796,6 +795,7 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
file_oomem(ms,
strlen(fn) + strlen(d->d_name) + 2);
errs++;
closedir(dir);
goto out;
}
if (stat(mfn, &st) == -1 || !S_ISREG(st.st_mode)) {
@ -810,6 +810,7 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
realloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
free(mfn);
closedir(dir);
errs++;
goto out;
}
@ -2306,7 +2307,7 @@ private int
apprentice_compile(struct magic_set *ms, struct magic **magicp,
uint32_t *nmagicp, const char *fn)
{
int fd;
int fd = -1;
char *dbname;
int rv = -1;
@ -2337,7 +2338,8 @@ apprentice_compile(struct magic_set *ms, struct magic **magicp,
goto out;
}
(void)close(fd);
if (fd != -1)
(void)close(fd);
rv = 0;
out:
free(dbname);

View File

@ -1,4 +1,4 @@
/* $NetBSD: cdf.c,v 1.5 2011/09/16 21:06:26 christos Exp $ */
/* $NetBSD: cdf.c,v 1.6 2012/02/22 17:53:51 christos Exp $ */
/*-
* Copyright (c) 2008 Christos Zoulas
@ -38,9 +38,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: cdf.c,v 1.45 2011/08/28 08:38:48 christos Exp $")
FILE_RCSID("@(#)$File: cdf.c,v 1.50 2012/02/20 22:35:29 christos Exp $")
#else
__RCSID("$NetBSD: cdf.c,v 1.5 2011/09/16 21:06:26 christos Exp $");
__RCSID("$NetBSD: cdf.c,v 1.6 2012/02/22 17:53:51 christos Exp $");
#endif
#endif
@ -63,10 +63,6 @@ __RCSID("$NetBSD: cdf.c,v 1.5 2011/09/16 21:06:26 christos Exp $");
#include "cdf.h"
#ifndef __arraycount
#define __arraycount(a) (sizeof(a) / sizeof(a[0]))
#endif
#ifdef CDF_DEBUG
#define DPRINTF(a) printf a, fflush(stdout)
#else
@ -85,6 +81,7 @@ static union {
#define CDF_TOLE2(x) ((uint16_t)(NEED_SWAP ? _cdf_tole2(x) : (uint16_t)(x)))
#define CDF_GETUINT32(x, y) cdf_getuint32(x, y)
/*
* swap a short
*/
@ -351,18 +348,27 @@ ssize_t
cdf_read_sector(const cdf_info_t *info, void *buf, size_t offs, size_t len,
const cdf_header_t *h, cdf_secid_t id)
{
assert((size_t)CDF_SEC_SIZE(h) == len);
return cdf_read(info, (off_t)CDF_SEC_POS(h, id),
((char *)buf) + offs, len);
size_t ss = CDF_SEC_SIZE(h);
size_t pos = CDF_SEC_POS(h, id);
assert(ss == len);
return cdf_read(info, (off_t)pos, ((char *)buf) + offs, len);
}
ssize_t
cdf_read_short_sector(const cdf_stream_t *sst, void *buf, size_t offs,
size_t len, const cdf_header_t *h, cdf_secid_t id)
{
assert((size_t)CDF_SHORT_SEC_SIZE(h) == len);
size_t ss = CDF_SHORT_SEC_SIZE(h);
size_t pos = CDF_SHORT_SEC_POS(h, id);
assert(ss == len);
if (pos > CDF_SEC_SIZE(h) * sst->sst_len) {
DPRINTF(("Out of bounds read %" SIZE_T_FORMAT "u > %"
SIZE_T_FORMAT "u\n",
pos, CDF_SEC_SIZE(h) * sst->sst_len));
return -1;
}
(void)memcpy(((char *)buf) + offs,
((const char *)sst->sst_tab) + CDF_SHORT_SEC_POS(h, id), len);
((const char *)sst->sst_tab) + pos, len);
return len;
}
@ -429,8 +435,8 @@ cdf_read_sat(const cdf_info_t *info, cdf_header_t *h, cdf_sat_t *sat)
if (sec < 0)
goto out;
if (i >= sat->sat_len) {
DPRINTF(("Out of bounds reading MSA %u >= %u",
i, sat->sat_len));
DPRINTF(("Out of bounds reading MSA %" SIZE_T_FORMAT
"u >= %" SIZE_T_FORMAT "u", i, sat->sat_len));
errno = EFTYPE;
goto out2;
}
@ -503,7 +509,8 @@ cdf_read_long_sector_chain(const cdf_info_t *info, const cdf_header_t *h,
}
if (i >= scn->sst_len) {
DPRINTF(("Out of bounds reading long sector chain "
"%u > %u\n", i, scn->sst_len));
"%" SIZE_T_FORMAT "u > %" SIZE_T_FORMAT "u\n", i,
scn->sst_len));
errno = EFTYPE;
goto out;
}
@ -548,7 +555,8 @@ cdf_read_short_sector_chain(const cdf_header_t *h,
}
if (i >= scn->sst_len) {
DPRINTF(("Out of bounds reading short sector chain "
"%u > %u\n", i, scn->sst_len));
"%" SIZE_T_FORMAT "u > %" SIZE_T_FORMAT "u\n",
i, scn->sst_len));
errno = EFTYPE;
goto out;
}
@ -656,7 +664,8 @@ cdf_read_ssat(const cdf_info_t *info, const cdf_header_t *h,
}
if (i >= ssat->sat_len) {
DPRINTF(("Out of bounds reading short sector chain "
"%u > %u\n", i, ssat->sat_len));
"%" SIZE_T_FORMAT "u > %" SIZE_T_FORMAT "u\n", i,
ssat->sat_len));
errno = EFTYPE;
goto out;
}
@ -796,17 +805,18 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
if (cdf_check_stream_offset(sst, h, e, 0, __LINE__) == -1)
goto out;
for (i = 0; i < sh.sh_properties; i++) {
size_t ofs = CDF_GETUINT32(p, (i << 1) + 1);
q = (const uint8_t *)(const void *)
((const char *)(const void *)p +
CDF_GETUINT32(p, (i << 1) + 1)) - 2 * sizeof(uint32_t);
((const char *)(const void *)p + ofs
- 2 * sizeof(uint32_t));
if (q > e) {
DPRINTF(("Ran of the end %p > %p\n", q, e));
goto out;
}
inp[i].pi_id = CDF_GETUINT32(p, i << 1);
inp[i].pi_type = CDF_GETUINT32(q, 0);
DPRINTF(("%d) id=%x type=%x offs=%x,%d\n", i, inp[i].pi_id,
inp[i].pi_type, q - p, CDF_GETUINT32(p, (i << 1) + 1)));
DPRINTF(("%" SIZE_T_FORMAT "u) id=%x type=%x offs=0x%tx,0x%x\n",
i, inp[i].pi_id, inp[i].pi_type, q - p, offs));
if (inp[i].pi_type & CDF_VECTOR) {
nelements = CDF_GETUINT32(q, 1);
o = 2;
@ -852,6 +862,20 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
(void)memcpy(&u64, &q[o4], sizeof(u64));
inp[i].pi_u64 = CDF_TOLE8((uint64_t)u64);
break;
case CDF_FLOAT:
if (inp[i].pi_type & CDF_VECTOR)
goto unknown;
(void)memcpy(&u32, &q[o4], sizeof(u32));
u32 = CDF_TOLE4(u32);
memcpy(&inp[i].pi_f, &u32, sizeof(inp[i].pi_f));
break;
case CDF_DOUBLE:
if (inp[i].pi_type & CDF_VECTOR)
goto unknown;
(void)memcpy(&u64, &q[o4], sizeof(u64));
u64 = CDF_TOLE8((uint64_t)u64);
memcpy(&inp[i].pi_d, &u64, sizeof(inp[i].pi_d));
break;
case CDF_LENGTH32_STRING:
case CDF_LENGTH32_WSTRING:
if (nelements > 1) {
@ -867,17 +891,22 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
*info = inp;
inp = *info + nelem;
}
DPRINTF(("nelements = %d\n", nelements));
DPRINTF(("nelements = %" SIZE_T_FORMAT "u\n",
nelements));
for (j = 0; j < nelements; j++, i++) {
uint32_t l = CDF_GETUINT32(q, o);
inp[i].pi_str.s_len = l;
inp[i].pi_str.s_buf = (const char *)
(const void *)(&q[o4 + sizeof(l)]);
DPRINTF(("l = %d, r = %d, s = %s\n", l,
DPRINTF(("l = %d, r = %" SIZE_T_FORMAT
"u, s = %s\n", l,
CDF_ROUND(l, sizeof(l)),
inp[i].pi_str.s_buf));
l = 4 + (uint32_t)CDF_ROUND(l, sizeof(l));
o += l >> 2;
if (l & 1)
l++;
o += l >> 1;
if (q + o >= e)
goto out;
o4 = o * sizeof(uint32_t);
}
i--;
@ -896,7 +925,7 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
unknown:
DPRINTF(("Don't know how to deal with %x\n",
inp[i].pi_type));
goto out;
break;
}
}
return 0;
@ -935,8 +964,9 @@ cdf_unpack_summary_info(const cdf_stream_t *sst, const cdf_header_t *h,
return -1;
}
if (cdf_read_property_info(sst, h, CDF_TOLE4(sd->sd_offset),
info, count, &maxcount) == -1)
info, count, &maxcount) == -1) {
return -1;
}
}
return 0;
}
@ -1061,14 +1091,14 @@ cdf_dump_sat(const char *prefix, const cdf_sat_t *sat, size_t size)
size_t i, j, s = size / sizeof(cdf_secid_t);
for (i = 0; i < sat->sat_len; i++) {
(void)fprintf(stderr, "%s[%" SIZE_T_FORMAT "u]:\n%.6d: ",
prefix, i, i * s);
(void)fprintf(stderr, "%s[%" SIZE_T_FORMAT "u]:\n%.6"
SIZE_T_FORMAT "u: ", prefix, i, i * s);
for (j = 0; j < s; j++) {
(void)fprintf(stderr, "%5d, ",
CDF_TOLE4(sat->sat_tab[s * i + j]));
if ((j + 1) % 10 == 0)
(void)fprintf(stderr, "\n%.6d: ",
i * s + j + 1);
(void)fprintf(stderr, "\n%.6" SIZE_T_FORMAT
"u: ", i * s + j + 1);
}
(void)fprintf(stderr, "\n");
}
@ -1087,7 +1117,8 @@ cdf_dump(void *v, size_t len)
if (j == 16) {
j = 0;
abuf[15] = '\0';
(void)fprintf(stderr, "%s\n%.4x: ", abuf, i + 1);
(void)fprintf(stderr, "%s\n%.4" SIZE_T_FORMAT "x: ",
abuf, i + 1);
}
}
(void)fprintf(stderr, "\n");
@ -1185,6 +1216,14 @@ cdf_dump_property_info(const cdf_property_info_t *info, size_t count)
(void)fprintf(stderr, "unsigned 32 [%u]\n",
info[i].pi_u32);
break;
case CDF_FLOAT:
(void)fprintf(stderr, "float [%g]\n",
info[i].pi_f);
break;
case CDF_DOUBLE:
(void)fprintf(stderr, "double [%g]\n",
info[i].pi_d);
break;
case CDF_LENGTH32_STRING:
(void)fprintf(stderr, "string %u [%.*s]\n",
info[i].pi_str.s_len,

View File

@ -1,4 +1,4 @@
/* $NetBSD: cdf_time.c,v 1.3 2011/05/13 01:52:13 christos Exp $ */
/* $NetBSD: cdf_time.c,v 1.4 2012/02/22 17:53:51 christos Exp $ */
/*-
* Copyright (c) 2008 Christos Zoulas
@ -30,9 +30,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: cdf_time.c,v 1.10 2011/02/10 17:03:16 christos Exp $")
FILE_RCSID("@(#)$File: cdf_time.c,v 1.11 2011/12/13 13:48:41 christos Exp $")
#else
__RCSID("$NetBSD: cdf_time.c,v 1.3 2011/05/13 01:52:13 christos Exp $");
__RCSID("$NetBSD: cdf_time.c,v 1.4 2012/02/22 17:53:51 christos Exp $");
#endif
#endif
@ -127,7 +127,7 @@ cdf_timestamp_to_timespec(struct timespec *ts, cdf_timestamp_t t)
tm.tm_year = (int)(CDF_BASE_YEAR + (t / 365));
rdays = cdf_getdays(tm.tm_year);
t -= rdays;
t -= rdays - 1;
tm.tm_mday = cdf_getday(tm.tm_year, (int)t);
tm.tm_mon = cdf_getmonth(tm.tm_year, (int)t);
tm.tm_wday = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: compress.c,v 1.4 2011/09/16 21:06:26 christos Exp $ */
/* $NetBSD: compress.c,v 1.5 2012/02/22 17:53:51 christos Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -38,9 +38,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: compress.c,v 1.67 2011/09/01 12:12:37 christos Exp $")
FILE_RCSID("@(#)$File: compress.c,v 1.68 2011/12/08 12:38:24 rrt Exp $")
#else
__RCSID("$NetBSD: compress.c,v 1.4 2011/09/16 21:06:26 christos Exp $");
__RCSID("$NetBSD: compress.c,v 1.5 2012/02/22 17:53:51 christos Exp $");
#endif
#endif
@ -140,8 +140,7 @@ file_zmagic(struct magic_set *ms, int fd, const char *name,
}
}
error:
if (newbuf)
free(newbuf);
free(newbuf);
ms->flags |= MAGIC_COMPRESS;
return rv;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: file.h,v 1.5 2011/09/16 21:06:26 christos Exp $ */
/* $NetBSD: file.h,v 1.6 2012/02/22 17:53:51 christos Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -29,7 +29,7 @@
*/
/*
* file.h - definitions for file(1) program
* @(#)$File: file.h,v 1.133 2011/05/13 22:15:40 christos Exp $
* @(#)$File: file.h,v 1.135 2011/09/20 15:30:14 christos Exp $
*/
#ifndef __file_h__
@ -88,6 +88,10 @@
#endif
#define public
#ifndef __arraycount
#define __arraycount(a) (sizeof(a) / sizeof(a[0]))
#endif
#ifndef __GNUC_PREREQ__
#ifdef __GNUC__
#define __GNUC_PREREQ__(x, y) \
@ -403,15 +407,16 @@ protected int file_trycdf(struct magic_set *, int, const unsigned char *,
protected int file_zmagic(struct magic_set *, int, const char *,
const unsigned char *, size_t);
#endif
protected int file_ascmagic(struct magic_set *, const unsigned char *, size_t);
protected int file_ascmagic(struct magic_set *, const unsigned char *, size_t,
int);
protected int file_ascmagic_with_encoding(struct magic_set *,
const unsigned char *, size_t, unichar *, size_t, const char *,
const char *);
const char *, int);
protected int file_encoding(struct magic_set *, const unsigned char *, size_t,
unichar **, size_t *, const char **, const char **, const char **);
protected int file_is_tar(struct magic_set *, const unsigned char *, size_t);
protected int file_softmagic(struct magic_set *, const unsigned char *, size_t,
int);
int, int);
protected struct mlist *file_apprentice(struct magic_set *, const char *, int);
protected uint64_t file_signextend(struct magic_set *, struct magic *,
uint64_t);

View File

@ -1,4 +1,4 @@
/* $NetBSD: funcs.c,v 1.3 2011/05/13 01:52:13 christos Exp $ */
/* $NetBSD: funcs.c,v 1.4 2012/02/22 17:53:51 christos Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
@ -30,9 +30,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: funcs.c,v 1.57 2011/05/11 01:02:41 christos Exp $")
FILE_RCSID("@(#)$File: funcs.c,v 1.60 2011/12/08 12:38:24 rrt Exp $")
#else
__RCSID("$NetBSD: funcs.c,v 1.3 2011/05/13 01:52:13 christos Exp $");
__RCSID("$NetBSD: funcs.c,v 1.4 2012/02/22 17:53:51 christos Exp $");
#endif
#endif /* lint */
@ -235,7 +235,8 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((__u
/* try soft magic tests */
if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0)
if ((m = file_softmagic(ms, ubuf, nb, BINTEST)) != 0) {
if ((m = file_softmagic(ms, ubuf, nb, BINTEST,
looks_text)) != 0) {
if ((ms->flags & MAGIC_DEBUG) != 0)
(void)fprintf(stderr, "softmagic %d\n", m);
#ifdef BUILTIN_ELF
@ -259,10 +260,10 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((__u
goto done;
}
/* try text properties (and possibly text tokens) */
/* try text properties */
if ((ms->flags & MAGIC_NO_CHECK_TEXT) == 0) {
if ((m = file_ascmagic(ms, ubuf, nb)) != 0) {
if ((m = file_ascmagic(ms, ubuf, nb, looks_text)) != 0) {
if ((ms->flags & MAGIC_DEBUG) != 0)
(void)fprintf(stderr, "ascmagic %d\n", m);
goto done;
@ -272,7 +273,8 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((__u
if ((ms->flags & MAGIC_NO_CHECK_ENCODING) == 0) {
if (looks_text == 0)
if ((m = file_ascmagic_with_encoding( ms, ubuf,
nb, u8buf, ulen, code, type)) != 0) {
nb, u8buf, ulen, code, type, looks_text))
!= 0) {
if ((ms->flags & MAGIC_DEBUG) != 0)
(void)fprintf(stderr,
"ascmagic/enc %d\n", m);
@ -295,8 +297,7 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((__u
if (file_printf(ms, "%s", code_mime) == -1)
rv = -1;
}
if (u8buf)
free(u8buf);
free(u8buf);
if (rv)
return rv;

View File

@ -1,178 +0,0 @@
/* $NetBSD: names.h,v 1.1.1.2 2011/05/12 20:46:54 christos Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
* maintained 1995-present by Christos Zoulas and others.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice immediately at the beginning of the file, without modification,
* this list of conditions, and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Names.h - names and types used by ascmagic in file(1).
* These tokens are here because they can appear anywhere in
* the first HOWMANY bytes, while tokens in MAGIC must
* appear at fixed offsets into the file. Don't make HOWMANY
* too high unless you have a very fast CPU.
*
* $File: names.h,v 1.33 2010/10/08 21:58:44 christos Exp $
*/
/*
modified by Chris Lowth - 9 April 2000
to add mime type strings to the types table.
*/
/* these types are used to index the table 'types': keep em in sync! */
#define L_C 0 /* first and foremost on UNIX */
#define L_CC 1 /* Bjarne's postincrement */
#define L_MAKE 2 /* Makefiles */
#define L_PLI 3 /* PL/1 */
#define L_MACH 4 /* some kinda assembler */
#define L_ENG 5 /* English */
#define L_PAS 6 /* Pascal */
#define L_MAIL 7 /* Electronic mail */
#define L_NEWS 8 /* Usenet Netnews */
#define L_JAVA 9 /* Java code */
#define L_HTML 10 /* HTML */
#define L_BCPL 11 /* BCPL */
#define L_M4 12 /* M4 */
#define L_PO 13 /* PO */
static const struct {
char human[48];
char mime[16];
} types[] = {
{ "C program", "text/x-c", },
{ "C++ program", "text/x-c++" },
{ "make commands", "text/x-makefile" },
{ "PL/1 program", "text/x-pl1" },
{ "assembler program", "text/x-asm" },
{ "English", "text/plain" },
{ "Pascal program", "text/x-pascal" },
{ "mail", "text/x-mail" },
{ "news", "text/x-news" },
{ "Java program", "text/x-java" },
{ "HTML document", "text/html", },
{ "BCPL program", "text/x-bcpl" },
{ "M4 macro language pre-processor", "text/x-m4" },
{ "PO (gettext message catalogue)", "text/x-po" },
{ "cannot happen error on names.h/types", "error/x-error" }
};
/*
* XXX - how should we distinguish Java from C++?
* The trick used in a Debian snapshot, of having "extends" or "implements"
* as tags for Java, doesn't work very well, given that those keywords
* are often preceded by "class", which flags it as C++.
*
* Perhaps we need to be able to say
*
* If "class" then
*
* if "extends" or "implements" then
* Java
* else
* C++
* endif
*
* Or should we use other keywords, such as "package" or "import"?
* Unfortunately, Ada95 uses "package", and Modula-3 uses "import",
* although I infer from the language spec at
*
* http://www.research.digital.com/SRC/m3defn/html/m3.html
*
* that Modula-3 uses "IMPORT" rather than "import", i.e. it must be
* in all caps.
*
* So, for now, we go with "import". We must put it before the C++
* stuff, so that we don't misidentify Java as C++. Not using "package"
* means we won't identify stuff that defines a package but imports
* nothing; hopefully, very little Java code imports nothing (one of the
* reasons for doing OO programming is to import as much as possible
* and write only what you need to, right?).
*
* Unfortunately, "import" may cause us to misidentify English text
* as Java, as it comes after "the" and "The". Perhaps we need a fancier
* heuristic to identify Java?
*/
static const struct names {
char name[14];
unsigned char type;
unsigned char score;
} names[] = {
/* These must be sorted by eye for optimal hit rate */
/* Add to this list only after substantial meditation */
{"msgid", L_PO, 1 },
{"dnl", L_M4, 2 },
{"import", L_JAVA, 2 },
{"\"libhdr\"", L_BCPL, 2 },
{"\"LIBHDR\"", L_BCPL, 2 },
{"//", L_CC, 2 },
{"template", L_CC, 1 },
{"virtual", L_CC, 1 },
{"class", L_CC, 2 },
{"public:", L_CC, 2 },
{"private:", L_CC, 2 },
{"/*", L_C, 2 }, /* must precede "The", "the", etc. */
{"#include", L_C, 2 },
{"char", L_C, 2 },
{"The", L_ENG, 2 },
{"the", L_ENG, 2 },
{"double", L_C, 1 },
{"extern", L_C, 2 },
{"float", L_C, 1 },
{"struct", L_C, 1 },
{"union", L_C, 1 },
{"main(", L_C, 2 },
{"CFLAGS", L_MAKE, 2 },
{"LDFLAGS", L_MAKE, 2 },
{"all:", L_MAKE, 2 },
{".PRECIOUS", L_MAKE, 2 },
{".ascii", L_MACH, 2 },
{".asciiz", L_MACH, 2 },
{".byte", L_MACH, 2 },
{".even", L_MACH, 2 },
{".globl", L_MACH, 2 },
{".text", L_MACH, 2 },
{"clr", L_MACH, 2 },
{"(input,", L_PAS, 2 },
{"program", L_PAS, 1 },
{"record", L_PAS, 1 },
{"dcl", L_PLI, 2 },
{"Received:", L_MAIL, 2 },
{">From", L_MAIL, 2 },
{"Return-Path:",L_MAIL, 2 },
{"Cc:", L_MAIL, 2 },
{"Newsgroups:", L_NEWS, 2 },
{"Path:", L_NEWS, 2 },
{"Organization:",L_NEWS, 2 },
{"href=", L_HTML, 2 },
{"HREF=", L_HTML, 2 },
{"<body", L_HTML, 2 },
{"<BODY", L_HTML, 2 },
{"<html", L_HTML, 2 },
{"<HTML", L_HTML, 2 },
{"<!--", L_HTML, 2 },
};
#define NNAMES (sizeof(names)/sizeof(struct names))

View File

@ -1,4 +1,4 @@
/* $NetBSD: print.c,v 1.3 2011/09/16 21:06:26 christos Exp $ */
/* $NetBSD: print.c,v 1.4 2012/02/22 17:53:51 christos Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -35,9 +35,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: print.c,v 1.70 2011/08/14 09:03:12 christos Exp $")
FILE_RCSID("@(#)$File: print.c,v 1.71 2011/09/20 15:28:09 christos Exp $")
#else
__RCSID("$NetBSD: print.c,v 1.3 2011/09/16 21:06:26 christos Exp $");
__RCSID("$NetBSD: print.c,v 1.4 2012/02/22 17:53:51 christos Exp $");
#endif
#endif /* lint */
@ -57,8 +57,8 @@ file_mdump(struct magic *m)
{
private const char optyp[] = { FILE_OPS };
(void) fprintf(stderr, "%.*s %u", (m->cont_level & 7) + 1, ">>>>>>>>",
m->offset);
(void) fprintf(stderr, "%u: %.*s %u", m->lineno,
(m->cont_level & 7) + 1, ">>>>>>>>", m->offset);
if (m->flag & INDIR) {
(void) fprintf(stderr, "(%s,",
@ -93,6 +93,24 @@ file_mdump(struct magic *m)
(void) fputc(CHAR_IGNORE_UPPERCASE, stderr);
if (m->str_flags & REGEX_OFFSET_START)
(void) fputc(CHAR_REGEX_OFFSET_START, stderr);
if (m->str_flags & STRING_TEXTTEST)
(void) fputc(CHAR_TEXTTEST, stderr);
if (m->str_flags & STRING_BINTEST)
(void) fputc(CHAR_BINTEST, stderr);
if (m->str_flags & PSTRING_1_BE)
(void) fputc(CHAR_PSTRING_1_BE, stderr);
if (m->str_flags & PSTRING_2_BE)
(void) fputc(CHAR_PSTRING_2_BE, stderr);
if (m->str_flags & PSTRING_2_LE)
(void) fputc(CHAR_PSTRING_2_LE, stderr);
if (m->str_flags & PSTRING_4_BE)
(void) fputc(CHAR_PSTRING_4_BE, stderr);
if (m->str_flags & PSTRING_4_LE)
(void) fputc(CHAR_PSTRING_4_LE, stderr);
if (m->str_flags & PSTRING_LENGTH_INCLUDES_ITSELF)
(void) fputc(
CHAR_PSTRING_LENGTH_INCLUDES_ITSELF,
stderr);
}
if (m->str_range)
(void) fprintf(stderr, "/%u", m->str_range);

View File

@ -1,4 +1,4 @@
/* $NetBSD: readcdf.c,v 1.6 2011/09/28 13:50:09 christos Exp $ */
/* $NetBSD: readcdf.c,v 1.7 2012/02/22 17:53:51 christos Exp $ */
/*-
* Copyright (c) 2008 Christos Zoulas
@ -29,9 +29,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: readcdf.c,v 1.26 2011/08/26 13:38:28 christos Exp $")
FILE_RCSID("@(#)$File: readcdf.c,v 1.29 2012/02/20 20:04:58 christos Exp $")
#else
__RCSID("$NetBSD: readcdf.c,v 1.6 2011/09/28 13:50:09 christos Exp $");
__RCSID("$NetBSD: readcdf.c,v 1.7 2012/02/22 17:53:51 christos Exp $");
#endif
#endif
@ -82,6 +82,16 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
info[i].pi_u32) == -1)
return -1;
break;
case CDF_FLOAT:
if (NOTMIME(ms) && file_printf(ms, ", %s: %g", buf,
info[i].pi_f) == -1)
return -1;
break;
case CDF_DOUBLE:
if (NOTMIME(ms) && file_printf(ms, ", %s: %g", buf,
info[i].pi_d) == -1)
return -1;
break;
case CDF_LENGTH32_STRING:
case CDF_LENGTH32_WSTRING:
len = info[i].pi_str.s_len;
@ -154,9 +164,8 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
if (!NOTMIME(ms)) {
if (str == NULL)
return 0;
if (file_printf(ms, "application/%s", str) == -1)
return -1;
if (file_printf(ms, "application/%s", str) == -1)
return -1;
}
return 1;
}
@ -174,30 +183,31 @@ cdf_file_summary_info(struct magic_set *ms, const cdf_header_t *h,
return -1;
if (NOTMIME(ms)) {
if (file_printf(ms, "Composite Document File V2 Document") == -1)
if (file_printf(ms, "Composite Document File V2 Document")
== -1)
return -1;
if (file_printf(ms, ", %s Endian",
si.si_byte_order == 0xfffe ? "Little" : "Big") == -1)
return -1;
return -2;
switch (si.si_os) {
case 2:
if (file_printf(ms, ", Os: Windows, Version %d.%d",
si.si_os_version & 0xff,
(uint32_t)si.si_os_version >> 8) == -1)
return -1;
return -2;
break;
case 1:
if (file_printf(ms, ", Os: MacOS, Version %d.%d",
(uint32_t)si.si_os_version >> 8,
si.si_os_version & 0xff) == -1)
return -1;
return -2;
break;
default:
if (file_printf(ms, ", Os %d, Version: %d.%d", si.si_os,
si.si_os_version & 0xff,
(uint32_t)si.si_os_version >> 8) == -1)
return -1;
return -2;
break;
}
}
@ -205,7 +215,7 @@ cdf_file_summary_info(struct magic_set *ms, const cdf_header_t *h,
m = cdf_file_property_info(ms, info, count);
free(info);
return m;
return m == -1 ? -2 : m;
}
protected int
@ -274,7 +284,7 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
#ifdef CDF_DEBUG
cdf_dump_summary_info(&h, &scn);
#endif
if ((i = cdf_file_summary_info(ms, &h, &scn)) == -1)
if ((i = cdf_file_summary_info(ms, &h, &scn)) < 0)
expn = "Can't expand summary_info";
if (i == 0) {
const char *str = "vnd.ms-office";
@ -305,8 +315,10 @@ out1:
free(sat.sat_tab);
out0:
if (i != 1) {
if (file_printf(ms, "Composite Document File V2 Document") == -1)
return -1;
if (i == -1)
if (file_printf(ms, "Composite Document File V2 Document")
== -1)
return -1;
if (*expn)
if (file_printf(ms, ", %s%s", corrupt, expn) == -1)
return -1;

View File

@ -1,4 +1,4 @@
/* $NetBSD: softmagic.c,v 1.4 2011/09/16 21:06:27 christos Exp $ */
/* $NetBSD: softmagic.c,v 1.5 2012/02/22 17:53:51 christos Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -35,9 +35,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: softmagic.c,v 1.145 2011/05/13 22:15:40 christos Exp $")
FILE_RCSID("@(#)$File: softmagic.c,v 1.147 2011/11/05 15:44:22 rrt Exp $")
#else
__RCSID("$NetBSD: softmagic.c,v 1.4 2011/09/16 21:06:27 christos Exp $");
__RCSID("$NetBSD: softmagic.c,v 1.5 2012/02/22 17:53:51 christos Exp $");
#endif
#endif /* lint */
@ -49,9 +49,9 @@ __RCSID("$NetBSD: softmagic.c,v 1.4 2011/09/16 21:06:27 christos Exp $");
private int match(struct magic_set *, struct magic *, uint32_t,
const unsigned char *, size_t, int);
const unsigned char *, size_t, int, int);
private int mget(struct magic_set *, const unsigned char *,
struct magic *, size_t, unsigned int);
struct magic *, size_t, unsigned int, int);
private int magiccheck(struct magic_set *, struct magic *);
private int32_t mprint(struct magic_set *, struct magic *);
private int32_t moffset(struct magic_set *, struct magic *);
@ -72,12 +72,14 @@ private void cvt_64(union VALUETYPE *, const struct magic *);
*/
/*ARGSUSED1*/ /* nbytes passed for regularity, maybe need later */
protected int
file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes, int mode)
file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
int mode, int text)
{
struct mlist *ml;
int rv;
for (ml = ms->mlist->next; ml != ms->mlist; ml = ml->next)
if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes, mode)) != 0)
if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes, mode,
text)) != 0)
return rv;
return 0;
@ -112,7 +114,7 @@ file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes, in
*/
private int
match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
const unsigned char *s, size_t nbytes, int mode)
const unsigned char *s, size_t nbytes, int mode, int text)
{
uint32_t magindex = 0;
unsigned int cont_level = 0;
@ -129,7 +131,10 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
int flush = 0;
struct magic *m = &magic[magindex];
if ((m->flag & mode) != mode) {
if ((IS_STRING(m->type) &&
((text && (m->str_flags & (STRING_BINTEST | STRING_TEXTTEST)) == STRING_BINTEST) ||
(!text && (m->str_flags & (STRING_TEXTTEST | STRING_BINTEST)) == STRING_TEXTTEST))) ||
(m->flag & mode) != mode) {
/* Skip sub-tests */
while (magic[magindex + 1].cont_level != 0 &&
++magindex < nmagic)
@ -141,7 +146,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
ms->line = m->lineno;
/* if main entry matches, print it... */
switch (mget(ms, s, m, nbytes, cont_level)) {
switch (mget(ms, s, m, nbytes, cont_level, text)) {
case -1:
return -1;
case 0:
@ -224,7 +229,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
continue;
}
#endif
switch (mget(ms, s, m, nbytes, cont_level)) {
switch (mget(ms, s, m, nbytes, cont_level, text)) {
case -1:
return -1;
case 0:
@ -1019,7 +1024,7 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
private int
mget(struct magic_set *ms, const unsigned char *s,
struct magic *m, size_t nbytes, unsigned int cont_level)
struct magic *m, size_t nbytes, unsigned int cont_level, int text)
{
uint32_t offset = ms->offset;
uint32_t count = m->str_range;
@ -1584,7 +1589,7 @@ mget(struct magic_set *ms, const unsigned char *s,
if (nbytes < offset)
return 0;
return file_softmagic(ms, s + offset, nbytes - offset,
BINTEST);
BINTEST, text);
case FILE_DEFAULT: /* nothing to check */
default: