summaryrefslogtreecommitdiffstats
path: root/contrib/file/src
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/file/src')
-rw-r--r--contrib/file/src/Makefile.am2
-rw-r--r--contrib/file/src/Makefile.in29
-rw-r--r--contrib/file/src/apprentice.c3
-rw-r--r--contrib/file/src/cdf.c10
-rw-r--r--contrib/file/src/compress.c5
-rw-r--r--contrib/file/src/der.c4
-rw-r--r--contrib/file/src/file.c8
-rw-r--r--contrib/file/src/magic.h126
-rw-r--r--contrib/file/src/softmagic.c6
9 files changed, 37 insertions, 156 deletions
diff --git a/contrib/file/src/Makefile.am b/contrib/file/src/Makefile.am
index 5891feb..155aec4 100644
--- a/contrib/file/src/Makefile.am
+++ b/contrib/file/src/Makefile.am
@@ -1,6 +1,6 @@
MAGIC = $(pkgdatadir)/magic
lib_LTLIBRARIES = libmagic.la
-include_HEADERS = magic.h
+nodist_include_HEADERS = magic.h
bin_PROGRAMS = file
diff --git a/contrib/file/src/Makefile.in b/contrib/file/src/Makefile.in
index a44bf88..b6eeb20 100644
--- a/contrib/file/src/Makefile.in
+++ b/contrib/file/src/Makefile.in
@@ -98,8 +98,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
-DIST_COMMON = $(srcdir)/Makefile.am $(include_HEADERS) \
- $(am__DIST_COMMON)
+DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
@@ -193,7 +192,7 @@ am__can_run_installinfo = \
n|no|NO) false;; \
*) (install-info --version) >/dev/null 2>&1;; \
esac
-HEADERS = $(include_HEADERS)
+HEADERS = $(nodist_include_HEADERS)
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
# Read a list of newline-separated strings from the standard input,
# and print each of them once, without duplicates. Input order is
@@ -340,7 +339,7 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
MAGIC = $(pkgdatadir)/magic
lib_LTLIBRARIES = libmagic.la
-include_HEADERS = magic.h
+nodist_include_HEADERS = magic.h
AM_CPPFLAGS = -DMAGIC='"$(MAGIC)"'
AM_CFLAGS = $(CFLAG_VISIBILITY) @WARNINGS@
libmagic_la_SOURCES = magic.c apprentice.c softmagic.c ascmagic.c \
@@ -551,9 +550,9 @@ mostlyclean-libtool:
clean-libtool:
-rm -rf .libs _libs
-install-includeHEADERS: $(include_HEADERS)
+install-nodist_includeHEADERS: $(nodist_include_HEADERS)
@$(NORMAL_INSTALL)
- @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \
+ @list='$(nodist_include_HEADERS)'; test -n "$(includedir)" || list=; \
if test -n "$$list"; then \
echo " $(MKDIR_P) '$(DESTDIR)$(includedir)'"; \
$(MKDIR_P) "$(DESTDIR)$(includedir)" || exit 1; \
@@ -567,9 +566,9 @@ install-includeHEADERS: $(include_HEADERS)
$(INSTALL_HEADER) $$files "$(DESTDIR)$(includedir)" || exit $$?; \
done
-uninstall-includeHEADERS:
+uninstall-nodist_includeHEADERS:
@$(NORMAL_UNINSTALL)
- @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \
+ @list='$(nodist_include_HEADERS)'; test -n "$(includedir)" || list=; \
files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
dir='$(DESTDIR)$(includedir)'; $(am__uninstall_files_from_dir)
@@ -721,7 +720,7 @@ info: info-am
info-am:
-install-data-am: install-includeHEADERS
+install-data-am: install-nodist_includeHEADERS
install-dvi: install-dvi-am
@@ -767,8 +766,8 @@ ps: ps-am
ps-am:
-uninstall-am: uninstall-binPROGRAMS uninstall-includeHEADERS \
- uninstall-libLTLIBRARIES
+uninstall-am: uninstall-binPROGRAMS uninstall-libLTLIBRARIES \
+ uninstall-nodist_includeHEADERS
.MAKE: all check install install-am install-strip
@@ -779,15 +778,15 @@ uninstall-am: uninstall-binPROGRAMS uninstall-includeHEADERS \
distclean-tags distdir dvi dvi-am html html-am info info-am \
install install-am install-binPROGRAMS install-data \
install-data-am install-dvi install-dvi-am install-exec \
- install-exec-am install-html install-html-am \
- install-includeHEADERS install-info install-info-am \
- install-libLTLIBRARIES install-man install-pdf install-pdf-am \
+ install-exec-am install-html install-html-am install-info \
+ install-info-am install-libLTLIBRARIES install-man \
+ install-nodist_includeHEADERS install-pdf install-pdf-am \
install-ps install-ps-am install-strip installcheck \
installcheck-am installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-compile \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags tags-am uninstall uninstall-am uninstall-binPROGRAMS \
- uninstall-includeHEADERS uninstall-libLTLIBRARIES
+ uninstall-libLTLIBRARIES uninstall-nodist_includeHEADERS
.PRECIOUS: Makefile
diff --git a/contrib/file/src/apprentice.c b/contrib/file/src/apprentice.c
index f8956de..e395854 100644
--- a/contrib/file/src/apprentice.c
+++ b/contrib/file/src/apprentice.c
@@ -32,7 +32,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.248 2016/03/31 17:51:12 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.249 2016/05/17 21:43:07 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -3104,6 +3104,7 @@ apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn)
(void)close(fd);
rv = 0;
out:
+ apprentice_unmap(map);
free(dbname);
return rv;
}
diff --git a/contrib/file/src/cdf.c b/contrib/file/src/cdf.c
index cc587fc..4ec65b4 100644
--- a/contrib/file/src/cdf.c
+++ b/contrib/file/src/cdf.c
@@ -35,7 +35,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: cdf.c,v 1.80 2016/05/06 15:17:10 christos Exp $")
+FILE_RCSID("@(#)$File: cdf.c,v 1.82 2016/06/01 22:25:25 christos Exp $")
#endif
#include <assert.h>
@@ -572,11 +572,11 @@ cdf_read_short_sector_chain(const cdf_header_t *h,
{
size_t ss = CDF_SHORT_SEC_SIZE(h), i, j;
scn->sst_tab = NULL;
- scn->sst_len = cdf_count_chain(ssat, sid, ss);
+ scn->sst_len = cdf_count_chain(ssat, sid, CDF_SEC_SIZE(h));
scn->sst_dirlen = len;
scn->sst_ss = ss;
- if (sst->sst_tab == NULL || scn->sst_len == (size_t)-1)
+ if (scn->sst_len == (size_t)-1)
goto out;
scn->sst_tab = calloc(scn->sst_len, ss);
@@ -683,7 +683,7 @@ cdf_read_ssat(const cdf_info_t *info, const cdf_header_t *h,
cdf_secid_t sid = h->h_secid_first_sector_in_short_sat;
ssat->sat_tab = NULL;
- ssat->sat_len = cdf_count_chain(sat, sid, CDF_SEC_SIZE(h));
+ ssat->sat_len = cdf_count_chain(sat, sid, ss);
if (ssat->sat_len == (size_t)-1)
goto out;
@@ -1068,6 +1068,8 @@ cdf_unpack_catalog(const cdf_header_t *h, const cdf_stream_t *sst,
if (b > eb)
break;
}
+ if (nr == 0)
+ return -1;
nr--;
*cat = CAST(cdf_catalog_t *,
malloc(sizeof(cdf_catalog_t) + nr * sizeof(*ce)));
diff --git a/contrib/file/src/compress.c b/contrib/file/src/compress.c
index 979443b..1988fe7 100644
--- a/contrib/file/src/compress.c
+++ b/contrib/file/src/compress.c
@@ -35,7 +35,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: compress.c,v 1.96 2016/04/20 00:00:26 christos Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.97 2016/05/13 23:02:28 christos Exp $")
#endif
#include "magic.h"
@@ -62,10 +62,9 @@ typedef void (*sig_t)(int);
#if defined(HAVE_SYS_TIME_H)
#include <sys/time.h>
#endif
-#if defined(HAVE_ZLIB_H) && defined(HAVE_LIBZ)
+#if defined(HAVE_ZLIB_H)
#define BUILTIN_DECOMPRESS
#include <zlib.h>
-#define ZLIBSUPPORT
#endif
#ifdef DEBUG
int tty = -1;
diff --git a/contrib/file/src/der.c b/contrib/file/src/der.c
index af5f149..f36606b 100644
--- a/contrib/file/src/der.c
+++ b/contrib/file/src/der.c
@@ -35,7 +35,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: der.c,v 1.6 2016/04/21 14:26:03 christos Exp $")
+FILE_RCSID("@(#)$File: der.c,v 1.7 2016/06/01 22:01:15 christos Exp $")
#endif
#endif
@@ -221,7 +221,7 @@ int32_t
der_offs(struct magic_set *ms, struct magic *m, size_t nbytes)
{
const uint8_t *b = CAST(const void *, ms->search.s);
- size_t offs = 0, len = ms->search.rm_len ? ms->search.rm_len : nbytes;
+ size_t offs = 0, len = ms->search.s_len ? ms->search.s_len : nbytes;
if (gettag(b, &offs, len) == DER_BAD)
return -1;
diff --git a/contrib/file/src/file.c b/contrib/file/src/file.c
index 2226ec4..9a8606d 100644
--- a/contrib/file/src/file.c
+++ b/contrib/file/src/file.c
@@ -32,7 +32,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: file.c,v 1.170 2016/03/31 17:51:12 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.171 2016/05/17 15:52:45 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -351,9 +351,10 @@ main(int argc, char *argv[])
if (c == -1) {
(void)fprintf(stderr, "%s: %s\n", progname,
magic_error(magic));
- return 1;
+ e = 1;
+ goto out;
}
- return 0;
+ goto out;
default:
if (magic == NULL)
if ((magic = load(magicfile, flags)) == NULL)
@@ -383,6 +384,7 @@ main(int argc, char *argv[])
e |= process(magic, argv[optind], wid);
}
+out:
if (magic)
magic_close(magic);
return e;
diff --git a/contrib/file/src/magic.h b/contrib/file/src/magic.h
deleted file mode 100644
index 3ba1f12..0000000
--- a/contrib/file/src/magic.h
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (c) Christos Zoulas 2003.
- * All Rights Reserved.
- *
- * 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.
- */
-#ifndef _MAGIC_H
-#define _MAGIC_H
-
-#include <sys/types.h>
-
-#define MAGIC_NONE 0x0000000 /* No flags */
-#define MAGIC_DEBUG 0x0000001 /* Turn on debugging */
-#define MAGIC_SYMLINK 0x0000002 /* Follow symlinks */
-#define MAGIC_COMPRESS 0x0000004 /* Check inside compressed files */
-#define MAGIC_DEVICES 0x0000008 /* Look at the contents of devices */
-#define MAGIC_MIME_TYPE 0x0000010 /* Return the MIME type */
-#define MAGIC_CONTINUE 0x0000020 /* Return all matches */
-#define MAGIC_CHECK 0x0000040 /* Print warnings to stderr */
-#define MAGIC_PRESERVE_ATIME 0x0000080 /* Restore access time on exit */
-#define MAGIC_RAW 0x0000100 /* Don't convert unprintable chars */
-#define MAGIC_ERROR 0x0000200 /* Handle ENOENT etc as real errors */
-#define MAGIC_MIME_ENCODING 0x0000400 /* Return the MIME encoding */
-#define MAGIC_MIME (MAGIC_MIME_TYPE|MAGIC_MIME_ENCODING)
-#define MAGIC_APPLE 0x0000800 /* Return the Apple creator/type */
-#define MAGIC_EXTENSION 0x1000000 /* Return a /-separated list of
- * extensions */
-#define MAGIC_COMPRESS_TRANSP 0x2000000 /* Check inside compressed files
- * but not report compression */
-#define MAGIC_NODESC (MAGIC_EXTENSION|MAGIC_MIME|MAGIC_APPLE)
-
-#define MAGIC_NO_CHECK_COMPRESS 0x0001000 /* Don't check for compressed files */
-#define MAGIC_NO_CHECK_TAR 0x0002000 /* Don't check for tar files */
-#define MAGIC_NO_CHECK_SOFT 0x0004000 /* Don't check magic entries */
-#define MAGIC_NO_CHECK_APPTYPE 0x0008000 /* Don't check application type */
-#define MAGIC_NO_CHECK_ELF 0x0010000 /* Don't check for elf details */
-#define MAGIC_NO_CHECK_TEXT 0x0020000 /* Don't check for text files */
-#define MAGIC_NO_CHECK_CDF 0x0040000 /* Don't check for cdf files */
-#define MAGIC_NO_CHECK_TOKENS 0x0100000 /* Don't check tokens */
-#define MAGIC_NO_CHECK_ENCODING 0x0200000 /* Don't check text encodings */
-
-/* No built-in tests; only consult the magic file */
-#define MAGIC_NO_CHECK_BUILTIN ( \
- MAGIC_NO_CHECK_COMPRESS | \
- MAGIC_NO_CHECK_TAR | \
-/* MAGIC_NO_CHECK_SOFT | */ \
- MAGIC_NO_CHECK_APPTYPE | \
- MAGIC_NO_CHECK_ELF | \
- MAGIC_NO_CHECK_TEXT | \
- MAGIC_NO_CHECK_CDF | \
- MAGIC_NO_CHECK_TOKENS | \
- MAGIC_NO_CHECK_ENCODING | \
- 0 \
-)
-
-/* Defined for backwards compatibility (renamed) */
-#define MAGIC_NO_CHECK_ASCII MAGIC_NO_CHECK_TEXT
-
-/* Defined for backwards compatibility; do nothing */
-#define MAGIC_NO_CHECK_FORTRAN 0x000000 /* Don't check ascii/fortran */
-#define MAGIC_NO_CHECK_TROFF 0x000000 /* Don't check ascii/troff */
-
-#define MAGIC_VERSION 526 /* This implementation */
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct magic_set *magic_t;
-magic_t magic_open(int);
-void magic_close(magic_t);
-
-const char *magic_getpath(const char *, int);
-const char *magic_file(magic_t, const char *);
-const char *magic_descriptor(magic_t, int);
-const char *magic_buffer(magic_t, const void *, size_t);
-
-const char *magic_error(magic_t);
-int magic_setflags(magic_t, int);
-
-int magic_version(void);
-int magic_load(magic_t, const char *);
-int magic_load_buffers(magic_t, void **, size_t *, size_t);
-
-int magic_compile(magic_t, const char *);
-int magic_check(magic_t, const char *);
-int magic_list(magic_t, const char *);
-int magic_errno(magic_t);
-
-#define MAGIC_PARAM_INDIR_MAX 0
-#define MAGIC_PARAM_NAME_MAX 1
-#define MAGIC_PARAM_ELF_PHNUM_MAX 2
-#define MAGIC_PARAM_ELF_SHNUM_MAX 3
-#define MAGIC_PARAM_ELF_NOTES_MAX 4
-#define MAGIC_PARAM_REGEX_MAX 5
-#define MAGIC_PARAM_BYTES_MAX 6
-
-int magic_setparam(magic_t, int, const void *);
-int magic_getparam(magic_t, int, void *);
-
-#ifdef __cplusplus
-};
-#endif
-
-#endif /* _MAGIC_H */
diff --git a/contrib/file/src/softmagic.c b/contrib/file/src/softmagic.c
index 2ceb26c..644c9d9 100644
--- a/contrib/file/src/softmagic.c
+++ b/contrib/file/src/softmagic.c
@@ -32,7 +32,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.231 2016/04/21 15:23:31 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.234 2016/06/13 12:02:06 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -827,6 +827,7 @@ moffset(struct magic_set *ms, struct magic *m, size_t nbytes, int32_t *op)
"Bad DER offset %d nbytes=%zu",
o, nbytes);
}
+ *op = 0;
return 0;
}
break;
@@ -1181,6 +1182,8 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
switch (type) {
case FILE_DER:
case FILE_SEARCH:
+ if (offset > nbytes)
+ offset = nbytes;
ms->search.s = RCAST(const char *, s) + offset;
ms->search.s_len = nbytes - offset;
ms->search.offset = offset;
@@ -2077,6 +2080,7 @@ magiccheck(struct magic_set *ms, struct magic *m)
if (slen != 0) {
copy = malloc(slen);
if (copy == NULL) {
+ file_regfree(&rx);
file_error(ms, errno,
"can't allocate %" SIZE_T_FORMAT "u bytes",
slen);
OpenPOWER on IntegriCloud