summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/Makefile.in279
-rw-r--r--src/apprentice.c14
-rw-r--r--src/ascmagic.c3
-rw-r--r--src/buffer.c3
-rw-r--r--src/compress.c196
-rw-r--r--src/encoding.c3
-rw-r--r--src/file.c18
-rw-r--r--src/file.h3
-rw-r--r--src/file_opts.h7
-rw-r--r--src/fsmagic.c8
-rw-r--r--src/funcs.c23
-rw-r--r--src/is_csv.c197
-rw-r--r--src/magic.h.in2
-rw-r--r--src/readcdf.c11
-rw-r--r--src/readelf.c14
-rw-r--r--src/seccomp.c24
-rw-r--r--src/vasprintf.c4
18 files changed, 644 insertions, 169 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 2fbefdbfcb5b..3f67f2cf3490 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,8 +8,8 @@ AM_CPPFLAGS = -DMAGIC='"$(MAGIC)"'
AM_CFLAGS = $(CFLAG_VISIBILITY) @WARNINGS@
libmagic_la_SOURCES = buffer.c magic.c apprentice.c softmagic.c ascmagic.c \
- encoding.c compress.c is_json.c is_tar.c readelf.c print.c fsmagic.c \
- funcs.c file.h readelf.h tar.h apptype.c der.c der.h \
+ encoding.c compress.c is_csv.c is_json.c is_tar.c readelf.c print.c \
+ fsmagic.c funcs.c file.h readelf.h tar.h apptype.c der.c der.h \
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
if MINGW
diff --git a/src/Makefile.in b/src/Makefile.in
index 29567c470280..59f3b5e42072 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.15 from Makefile.am.
+# Makefile.in generated by automake 1.16.1 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2014 Free Software Foundation, Inc.
+# Copyright (C) 1994-2018 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -103,6 +103,9 @@ mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
+am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(libdir)" \
+ "$(DESTDIR)$(includedir)"
+PROGRAMS = $(bin_PROGRAMS)
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
@@ -130,15 +133,13 @@ am__uninstall_files_from_dir = { \
|| { echo " ( cd '$$dir' && rm -f" $$files ")"; \
$(am__cd) "$$dir" && rm -f $$files; }; \
}
-am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \
- "$(DESTDIR)$(includedir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
am__DEPENDENCIES_1 =
libmagic_la_DEPENDENCIES = $(LTLIBOBJS) $(am__DEPENDENCIES_1)
am_libmagic_la_OBJECTS = buffer.lo magic.lo apprentice.lo softmagic.lo \
- ascmagic.lo encoding.lo compress.lo is_json.lo is_tar.lo \
- readelf.lo print.lo fsmagic.lo funcs.lo apptype.lo der.lo \
- cdf.lo cdf_time.lo readcdf.lo
+ ascmagic.lo encoding.lo compress.lo is_csv.lo is_json.lo \
+ is_tar.lo readelf.lo print.lo fsmagic.lo funcs.lo apptype.lo \
+ der.lo cdf.lo cdf_time.lo readcdf.lo
libmagic_la_OBJECTS = $(am_libmagic_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
@@ -147,7 +148,6 @@ am__v_lt_1 =
libmagic_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(libmagic_la_LDFLAGS) $(LDFLAGS) -o $@
-PROGRAMS = $(bin_PROGRAMS)
am_file_OBJECTS = file.$(OBJEXT) seccomp.$(OBJEXT)
file_OBJECTS = $(am_file_OBJECTS)
file_DEPENDENCIES = libmagic.la
@@ -165,7 +165,25 @@ am__v_at_0 = @
am__v_at_1 =
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
-am__depfiles_maybe = depfiles
+am__maybe_remake_depfiles = depfiles
+am__depfiles_remade = $(DEPDIR)/asctime_r.Plo $(DEPDIR)/asprintf.Plo \
+ $(DEPDIR)/ctime_r.Plo $(DEPDIR)/dprintf.Plo \
+ $(DEPDIR)/fmtcheck.Plo $(DEPDIR)/getline.Plo \
+ $(DEPDIR)/getopt_long.Plo $(DEPDIR)/gmtime_r.Plo \
+ $(DEPDIR)/localtime_r.Plo $(DEPDIR)/pread.Plo \
+ $(DEPDIR)/strcasestr.Plo $(DEPDIR)/strlcat.Plo \
+ $(DEPDIR)/strlcpy.Plo $(DEPDIR)/vasprintf.Plo \
+ ./$(DEPDIR)/apprentice.Plo ./$(DEPDIR)/apptype.Plo \
+ ./$(DEPDIR)/ascmagic.Plo ./$(DEPDIR)/buffer.Plo \
+ ./$(DEPDIR)/cdf.Plo ./$(DEPDIR)/cdf_time.Plo \
+ ./$(DEPDIR)/compress.Plo ./$(DEPDIR)/der.Plo \
+ ./$(DEPDIR)/encoding.Plo ./$(DEPDIR)/file.Po \
+ ./$(DEPDIR)/fsmagic.Plo ./$(DEPDIR)/funcs.Plo \
+ ./$(DEPDIR)/is_csv.Plo ./$(DEPDIR)/is_json.Plo \
+ ./$(DEPDIR)/is_tar.Plo ./$(DEPDIR)/magic.Plo \
+ ./$(DEPDIR)/print.Plo ./$(DEPDIR)/readcdf.Plo \
+ ./$(DEPDIR)/readelf.Plo ./$(DEPDIR)/seccomp.Po \
+ ./$(DEPDIR)/softmagic.Plo
am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@@ -259,6 +277,7 @@ LIBTOOL = @LIBTOOL@
LIPO = @LIPO@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
+LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MINGW = @MINGW@
@@ -343,8 +362,8 @@ nodist_include_HEADERS = magic.h
AM_CPPFLAGS = -DMAGIC='"$(MAGIC)"'
AM_CFLAGS = $(CFLAG_VISIBILITY) @WARNINGS@
libmagic_la_SOURCES = buffer.c magic.c apprentice.c softmagic.c ascmagic.c \
- encoding.c compress.c is_json.c is_tar.c readelf.c print.c fsmagic.c \
- funcs.c file.h readelf.h tar.h apptype.c der.c der.h \
+ encoding.c compress.c is_csv.c is_json.c is_tar.c readelf.c print.c \
+ fsmagic.c funcs.c file.h readelf.h tar.h apptype.c der.c der.h \
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
@@ -379,8 +398,8 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
- echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
- cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
@@ -391,44 +410,6 @@ $(top_srcdir)/configure: $(am__configure_deps)
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):
-
-install-libLTLIBRARIES: $(lib_LTLIBRARIES)
- @$(NORMAL_INSTALL)
- @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
- list2=; for p in $$list; do \
- if test -f $$p; then \
- list2="$$list2 $$p"; \
- else :; fi; \
- done; \
- test -z "$$list2" || { \
- echo " $(MKDIR_P) '$(DESTDIR)$(libdir)'"; \
- $(MKDIR_P) "$(DESTDIR)$(libdir)" || exit 1; \
- echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \
- $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \
- }
-
-uninstall-libLTLIBRARIES:
- @$(NORMAL_UNINSTALL)
- @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
- for p in $$list; do \
- $(am__strip_dir) \
- echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \
- $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \
- done
-
-clean-libLTLIBRARIES:
- -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
- @list='$(lib_LTLIBRARIES)'; \
- locs=`for p in $$list; do echo $$p; done | \
- sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
- sort -u`; \
- test -z "$$locs" || { \
- echo rm -f $${locs}; \
- rm -f $${locs}; \
- }
-
-libmagic.la: $(libmagic_la_OBJECTS) $(libmagic_la_DEPENDENCIES) $(EXTRA_libmagic_la_DEPENDENCIES)
- $(AM_V_CCLD)$(libmagic_la_LINK) -rpath $(libdir) $(libmagic_la_OBJECTS) $(libmagic_la_LIBADD) $(LIBS)
install-binPROGRAMS: $(bin_PROGRAMS)
@$(NORMAL_INSTALL)
@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
@@ -479,6 +460,44 @@ clean-binPROGRAMS:
echo " rm -f" $$list; \
rm -f $$list
+install-libLTLIBRARIES: $(lib_LTLIBRARIES)
+ @$(NORMAL_INSTALL)
+ @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
+ list2=; for p in $$list; do \
+ if test -f $$p; then \
+ list2="$$list2 $$p"; \
+ else :; fi; \
+ done; \
+ test -z "$$list2" || { \
+ echo " $(MKDIR_P) '$(DESTDIR)$(libdir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(libdir)" || exit 1; \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \
+ }
+
+uninstall-libLTLIBRARIES:
+ @$(NORMAL_UNINSTALL)
+ @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
+ for p in $$list; do \
+ $(am__strip_dir) \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \
+ done
+
+clean-libLTLIBRARIES:
+ -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
+ @list='$(lib_LTLIBRARIES)'; \
+ locs=`for p in $$list; do echo $$p; done | \
+ sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
+ sort -u`; \
+ test -z "$$locs" || { \
+ echo rm -f $${locs}; \
+ rm -f $${locs}; \
+ }
+
+libmagic.la: $(libmagic_la_OBJECTS) $(libmagic_la_DEPENDENCIES) $(EXTRA_libmagic_la_DEPENDENCIES)
+ $(AM_V_CCLD)$(libmagic_la_LINK) -rpath $(libdir) $(libmagic_la_OBJECTS) $(libmagic_la_LIBADD) $(LIBS)
+
file$(EXEEXT): $(file_OBJECTS) $(file_DEPENDENCIES) $(EXTRA_file_DEPENDENCIES)
@rm -f file$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(file_OBJECTS) $(file_LDADD) $(LIBS)
@@ -489,40 +508,47 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
-@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/asctime_r.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/asprintf.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/ctime_r.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/dprintf.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/fmtcheck.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/getline.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/getopt_long.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/gmtime_r.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/localtime_r.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/pread.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strcasestr.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strlcat.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strlcpy.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/vasprintf.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/apprentice.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/apptype.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ascmagic.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/buffer.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdf.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdf_time.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/compress.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/der.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/encoding.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/file.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fsmagic.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/funcs.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/is_json.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/is_tar.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/magic.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/print.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readcdf.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readelf.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/seccomp.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/softmagic.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/asctime_r.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/asprintf.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/ctime_r.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/dprintf.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/fmtcheck.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/getline.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/getopt_long.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/gmtime_r.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/localtime_r.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/pread.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strcasestr.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strlcat.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strlcpy.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/vasprintf.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/apprentice.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/apptype.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ascmagic.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/buffer.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdf.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdf_time.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/compress.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/der.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/encoding.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/file.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fsmagic.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/funcs.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/is_csv.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/is_json.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/is_tar.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/magic.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/print.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readcdf.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readelf.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/seccomp.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/softmagic.Plo@am__quote@ # am--include-marker
+
+$(am__depfiles_remade):
+ @$(MKDIR_P) $(@D)
+ @echo '# dummy' >$@-t && $(am__mv) $@-t $@
+
+am--depfiles: $(am__depfiles_remade)
.c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
@@ -627,7 +653,10 @@ cscopelist-am: $(am__tagged_files)
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
-distdir: $(DISTFILES)
+distdir: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) distdir-am
+
+distdir-am: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
@@ -660,11 +689,11 @@ distdir: $(DISTFILES)
check-am: all-am
check: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) check-am
-all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS)
+all-am: Makefile $(PROGRAMS) $(LTLIBRARIES) $(HEADERS)
install-binPROGRAMS: install-libLTLIBRARIES
installdirs:
- for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(includedir)"; do \
+ for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: $(BUILT_SOURCES)
@@ -706,7 +735,41 @@ clean-am: clean-binPROGRAMS clean-generic clean-libLTLIBRARIES \
clean-libtool mostlyclean-am
distclean: distclean-am
- -rm -rf $(DEPDIR) ./$(DEPDIR)
+ -rm -f $(DEPDIR)/asctime_r.Plo
+ -rm -f $(DEPDIR)/asprintf.Plo
+ -rm -f $(DEPDIR)/ctime_r.Plo
+ -rm -f $(DEPDIR)/dprintf.Plo
+ -rm -f $(DEPDIR)/fmtcheck.Plo
+ -rm -f $(DEPDIR)/getline.Plo
+ -rm -f $(DEPDIR)/getopt_long.Plo
+ -rm -f $(DEPDIR)/gmtime_r.Plo
+ -rm -f $(DEPDIR)/localtime_r.Plo
+ -rm -f $(DEPDIR)/pread.Plo
+ -rm -f $(DEPDIR)/strcasestr.Plo
+ -rm -f $(DEPDIR)/strlcat.Plo
+ -rm -f $(DEPDIR)/strlcpy.Plo
+ -rm -f $(DEPDIR)/vasprintf.Plo
+ -rm -f ./$(DEPDIR)/apprentice.Plo
+ -rm -f ./$(DEPDIR)/apptype.Plo
+ -rm -f ./$(DEPDIR)/ascmagic.Plo
+ -rm -f ./$(DEPDIR)/buffer.Plo
+ -rm -f ./$(DEPDIR)/cdf.Plo
+ -rm -f ./$(DEPDIR)/cdf_time.Plo
+ -rm -f ./$(DEPDIR)/compress.Plo
+ -rm -f ./$(DEPDIR)/der.Plo
+ -rm -f ./$(DEPDIR)/encoding.Plo
+ -rm -f ./$(DEPDIR)/file.Po
+ -rm -f ./$(DEPDIR)/fsmagic.Plo
+ -rm -f ./$(DEPDIR)/funcs.Plo
+ -rm -f ./$(DEPDIR)/is_csv.Plo
+ -rm -f ./$(DEPDIR)/is_json.Plo
+ -rm -f ./$(DEPDIR)/is_tar.Plo
+ -rm -f ./$(DEPDIR)/magic.Plo
+ -rm -f ./$(DEPDIR)/print.Plo
+ -rm -f ./$(DEPDIR)/readcdf.Plo
+ -rm -f ./$(DEPDIR)/readelf.Plo
+ -rm -f ./$(DEPDIR)/seccomp.Po
+ -rm -f ./$(DEPDIR)/softmagic.Plo
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
@@ -752,7 +815,41 @@ install-ps-am:
installcheck-am:
maintainer-clean: maintainer-clean-am
- -rm -rf $(DEPDIR) ./$(DEPDIR)
+ -rm -f $(DEPDIR)/asctime_r.Plo
+ -rm -f $(DEPDIR)/asprintf.Plo
+ -rm -f $(DEPDIR)/ctime_r.Plo
+ -rm -f $(DEPDIR)/dprintf.Plo
+ -rm -f $(DEPDIR)/fmtcheck.Plo
+ -rm -f $(DEPDIR)/getline.Plo
+ -rm -f $(DEPDIR)/getopt_long.Plo
+ -rm -f $(DEPDIR)/gmtime_r.Plo
+ -rm -f $(DEPDIR)/localtime_r.Plo
+ -rm -f $(DEPDIR)/pread.Plo
+ -rm -f $(DEPDIR)/strcasestr.Plo
+ -rm -f $(DEPDIR)/strlcat.Plo
+ -rm -f $(DEPDIR)/strlcpy.Plo
+ -rm -f $(DEPDIR)/vasprintf.Plo
+ -rm -f ./$(DEPDIR)/apprentice.Plo
+ -rm -f ./$(DEPDIR)/apptype.Plo
+ -rm -f ./$(DEPDIR)/ascmagic.Plo
+ -rm -f ./$(DEPDIR)/buffer.Plo
+ -rm -f ./$(DEPDIR)/cdf.Plo
+ -rm -f ./$(DEPDIR)/cdf_time.Plo
+ -rm -f ./$(DEPDIR)/compress.Plo
+ -rm -f ./$(DEPDIR)/der.Plo
+ -rm -f ./$(DEPDIR)/encoding.Plo
+ -rm -f ./$(DEPDIR)/file.Po
+ -rm -f ./$(DEPDIR)/fsmagic.Plo
+ -rm -f ./$(DEPDIR)/funcs.Plo
+ -rm -f ./$(DEPDIR)/is_csv.Plo
+ -rm -f ./$(DEPDIR)/is_json.Plo
+ -rm -f ./$(DEPDIR)/is_tar.Plo
+ -rm -f ./$(DEPDIR)/magic.Plo
+ -rm -f ./$(DEPDIR)/print.Plo
+ -rm -f ./$(DEPDIR)/readcdf.Plo
+ -rm -f ./$(DEPDIR)/readelf.Plo
+ -rm -f ./$(DEPDIR)/seccomp.Po
+ -rm -f ./$(DEPDIR)/softmagic.Plo
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
@@ -774,7 +871,7 @@ uninstall-am: uninstall-binPROGRAMS uninstall-libLTLIBRARIES \
.MAKE: all check install install-am install-strip
-.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean \
+.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \
clean-binPROGRAMS clean-generic clean-libLTLIBRARIES \
clean-libtool cscopelist-am ctags ctags-am distclean \
distclean-compile distclean-generic distclean-libtool \
diff --git a/src/apprentice.c b/src/apprentice.c
index eca3ae06af99..7ebd6897bd04 100644
--- a/src/apprentice.c
+++ b/src/apprentice.c
@@ -32,7 +32,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.283 2019/02/20 02:35:27 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.284 2019/06/29 22:31:04 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -1926,17 +1926,7 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
file_magwarn(ms, "offset `%s' invalid", l);
return -1;
}
-#if 0
- if (m->offset < 0 && cont_level != 0 &&
- (m->flag & (OFFADD | INDIROFFADD)) == 0) {
- if (ms->flags & MAGIC_CHECK) {
- file_magwarn(ms,
- "negative direct offset `%s' at level %u",
- l, cont_level);
- }
- return -1;
- }
-#endif
+
l = t;
if (m->flag & INDIR) {
diff --git a/src/ascmagic.c b/src/ascmagic.c
index 624ac90b1f1c..3bb7359777b9 100644
--- a/src/ascmagic.c
+++ b/src/ascmagic.c
@@ -35,12 +35,11 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: ascmagic.c,v 1.104 2019/05/07 02:27:11 christos Exp $")
+FILE_RCSID("@(#)$File: ascmagic.c,v 1.105 2019/06/08 20:49:14 christos Exp $")
#endif /* lint */
#include "magic.h"
#include <string.h>
-#include <memory.h>
#include <ctype.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
diff --git a/src/buffer.c b/src/buffer.c
index 6d8967d2fa73..0a27e5788483 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -27,7 +27,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: buffer.c,v 1.6 2019/05/07 02:27:11 christos Exp $")
+FILE_RCSID("@(#)$File: buffer.c,v 1.7 2019/06/10 21:35:26 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -77,6 +77,7 @@ buffer_fill(const struct buffer *bb)
b->eoff = b->st.st_size - b->elen;
if (pread(b->fd, b->ebuf, b->elen, b->eoff) == -1) {
free(b->ebuf);
+ b->ebuf = NULL;
goto out;
}
diff --git a/src/compress.c b/src/compress.c
index 95e42a24dd52..33ce2bc936d6 100644
--- a/src/compress.c
+++ b/src/compress.c
@@ -35,7 +35,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: compress.c,v 1.121 2019/05/07 02:27:11 christos Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.124 2019/07/21 11:42:09 christos Exp $")
#endif
#include "magic.h"
@@ -66,11 +66,16 @@ typedef void (*sig_t)(int);
#include <zlib.h>
#endif
-#if defined(HAVE_BZLIB_H)
+#if defined(HAVE_BZLIB_H) || defined(BZLIBSUPPORT)
#define BUILTIN_BZLIB
#include <bzlib.h>
#endif
+#if defined(HAVE_XZLIB_H) || defined(XZLIBSUPPORT)
+#define BUILTIN_XZLIB
+#include <lzma.h>
+#endif
+
#ifdef DEBUG
int tty = -1;
#define DPRINTF(...) do { \
@@ -113,6 +118,16 @@ zlibcmp(const unsigned char *buf)
}
#endif
+static int
+lzmacmp(const unsigned char *buf)
+{
+ if (buf[0] != 0x5d || buf[1] || buf[2])
+ return 0;
+ if (buf[12] && buf[12] != 0xff)
+ return 0;
+ return 1;
+}
+
#define gzip_flags "-cd"
#define lrzip_flags "-do"
#define lzip_flags gzip_flags
@@ -147,29 +162,35 @@ static const char *zstd_args[] = {
private const struct {
const void *magic;
- size_t maglen;
+ int maglen;
const char **argv;
void *unused;
} compr[] = {
- { "\037\235", 2, gzip_args, NULL }, /* compressed */
+#define METH_FROZEN 2
+#define METH_BZIP 7
+#define METH_XZ 9
+#define METH_LZMA 13
+#define METH_ZLIB 14
+ { "\037\235", 2, gzip_args, NULL }, /* 0, compressed */
/* Uncompress can get stuck; so use gzip first if we have it
* Idea from Damien Clark, thanks! */
- { "\037\235", 2, uncompress_args, NULL }, /* compressed */
- { "\037\213", 2, gzip_args, do_zlib }, /* gzipped */
- { "\037\236", 2, gzip_args, NULL }, /* frozen */
- { "\037\240", 2, gzip_args, NULL }, /* SCO LZH */
+ { "\037\235", 2, uncompress_args, NULL }, /* 1, compressed */
+ { "\037\213", 2, gzip_args, do_zlib }, /* 2, gzipped */
+ { "\037\236", 2, gzip_args, NULL }, /* 3, frozen */
+ { "\037\240", 2, gzip_args, NULL }, /* 4, SCO LZH */
/* the standard pack utilities do not accept standard input */
- { "\037\036", 2, gzip_args, NULL }, /* packed */
- { "PK\3\4", 4, gzip_args, NULL }, /* pkzipped, */
+ { "\037\036", 2, gzip_args, NULL }, /* 5, packed */
+ { "PK\3\4", 4, gzip_args, NULL }, /* 6, pkzipped, */
/* ...only first file examined */
- { "BZh", 3, bzip2_args, do_bzlib }, /* bzip2-ed */
- { "LZIP", 4, lzip_args, NULL }, /* lzip-ed */
- { "\3757zXZ\0", 6, xz_args, NULL }, /* XZ Utils */
- { "LRZI", 4, lrzip_args, NULL }, /* LRZIP */
- { "\004\"M\030",4, lz4_args, NULL }, /* LZ4 */
- { "\x28\xB5\x2F\xFD", 4, zstd_args, NULL }, /* zstd */
+ { "BZh", 3, bzip2_args, do_bzlib }, /* 7, bzip2-ed */
+ { "LZIP", 4, lzip_args, NULL }, /* 8, lzip-ed */
+ { "\3757zXZ\0", 6, xz_args, NULL }, /* 9, XZ Utils */
+ { "LRZI", 4, lrzip_args, NULL }, /* 10, LRZIP */
+ { "\004\"M\030",4, lz4_args, NULL }, /* 11, LZ4 */
+ { "\x28\xB5\x2F\xFD", 4, zstd_args, NULL }, /* 12, zstd */
+ { RCAST(const void *, lzmacmp), -13, xz_args, NULL }, /* 13, lzma */
#ifdef ZLIBSUPPORT
- { RCAST(const void *, zlibcmp), 0, zlib_args, NULL }, /* zlib */
+ { RCAST(const void *, zlibcmp), -2, zlib_args, NULL }, /* 14, zlib */
#endif
};
@@ -190,7 +211,11 @@ private int uncompressgzipped(const unsigned char *, unsigned char **, size_t,
#endif
#ifdef BUILTIN_BZLIB
private int uncompressbzlib(const unsigned char *, unsigned char **, size_t,
- size_t *, int);
+ size_t *);
+#endif
+#ifdef BUILTIN_XZLIB
+private int uncompressxzlib(const unsigned char *, unsigned char **, size_t,
+ size_t *);
#endif
static int makeerror(unsigned char **, size_t *, const char *, ...)
@@ -234,15 +259,15 @@ file_zmagic(struct magic_set *ms, const struct buffer *b, const char *name)
for (i = 0; i < ncompr; i++) {
int zm;
- if (nbytes < compr[i].maglen)
+ if (nbytes < CAST(size_t, abs(compr[i].maglen)))
continue;
-#ifdef ZLIBSUPPORT
- if (compr[i].maglen == 0)
+ if (compr[i].maglen < 0) {
zm = (RCAST(int (*)(const unsigned char *),
CCAST(void *, compr[i].magic)))(buf);
- else
-#endif
- zm = memcmp(buf, compr[i].magic, compr[i].maglen) == 0;
+ } else {
+ zm = memcmp(buf, compr[i].magic,
+ CAST(size_t, compr[i].maglen)) == 0;
+ }
if (!zm)
continue;
@@ -570,6 +595,90 @@ err:
}
#endif
+#ifdef BUILTIN_BZLIB
+private int
+uncompressbzlib(const unsigned char *old, unsigned char **newch,
+ size_t bytes_max, size_t *n)
+{
+ int rc;
+ bz_stream bz;
+
+ memset(&bz, 0, sizeof(bz));
+ rc = BZ2_bzDecompressInit(&bz, 0, 0);
+ if (rc != BZ_OK)
+ goto err;
+
+ if ((*newch = CAST(unsigned char *, malloc(bytes_max + 1))) == NULL)
+ return makeerror(newch, n, "No buffer, %s", strerror(errno));
+
+ bz.next_in = CCAST(char *, RCAST(const char *, old));
+ bz.avail_in = CAST(uint32_t, *n);
+ bz.next_out = RCAST(char *, *newch);
+ bz.avail_out = CAST(unsigned int, bytes_max);
+
+ rc = BZ2_bzDecompress(&bz);
+ if (rc != BZ_OK && rc != BZ_STREAM_END)
+ goto err;
+
+ /* Assume byte_max is within 32bit */
+ /* assert(bz.total_out_hi32 == 0); */
+ *n = CAST(size_t, bz.total_out_lo32);
+ rc = BZ2_bzDecompressEnd(&bz);
+ if (rc != BZ_OK)
+ goto err;
+
+ /* let's keep the nul-terminate tradition */
+ (*newch)[*n] = '\0';
+
+ return OKDATA;
+err:
+ snprintf(RCAST(char *, *newch), bytes_max, "bunzip error %d", rc);
+ *n = strlen(RCAST(char *, *newch));
+ return ERRDATA;
+}
+#endif
+
+#ifdef BUILTIN_XZLIB
+private int
+uncompressxzlib(const unsigned char *old, unsigned char **newch,
+ size_t bytes_max, size_t *n)
+{
+ int rc;
+ lzma_stream xz;
+
+ memset(&xz, 0, sizeof(xz));
+ rc = lzma_auto_decoder(&xz, UINT64_MAX, 0);
+ if (rc != LZMA_OK)
+ goto err;
+
+ if ((*newch = CAST(unsigned char *, malloc(bytes_max + 1))) == NULL)
+ return makeerror(newch, n, "No buffer, %s", strerror(errno));
+
+ xz.next_in = CCAST(const uint8_t *, old);
+ xz.avail_in = CAST(uint32_t, *n);
+ xz.next_out = RCAST(uint8_t *, *newch);
+ xz.avail_out = CAST(unsigned int, bytes_max);
+
+ rc = lzma_code(&xz, LZMA_RUN);
+ if (rc != LZMA_OK && rc != LZMA_STREAM_END)
+ goto err;
+
+ *n = CAST(size_t, xz.total_out);
+
+ lzma_end(&xz);
+
+ /* let's keep the nul-terminate tradition */
+ (*newch)[*n] = '\0';
+
+ return OKDATA;
+err:
+ snprintf(RCAST(char *, *newch), bytes_max, "unxz error %d", rc);
+ *n = strlen(RCAST(char *, *newch));
+ return ERRDATA;
+}
+#endif
+
+
static int
makeerror(unsigned char **buf, size_t *len, const char *fmt, ...)
{
@@ -676,12 +785,24 @@ filter_error(unsigned char *ubuf, ssize_t n)
private const char *
methodname(size_t method)
{
+ switch (method) {
#ifdef BUILTIN_DECOMPRESS
- /* FIXME: This doesn't cope with bzip2 */
- if (method == 2 || compr[method].maglen == 0)
- return "zlib";
+ case METH_FROZEN:
+ case METH_ZLIB:
+ return "zlib";
+#endif
+#ifdef BUILTIN_BZLIB
+ case METH_BZIP:
+ return "bzlib";
#endif
- return compr[method].argv[0];
+#ifdef BUILTIN_XZLIB
+ case METH_XZ:
+ case METH_LZMA:
+ return "xzlib";
+#endif
+ default:
+ return compr[method].argv[0];
+ }
}
private int
@@ -695,13 +816,26 @@ uncompressbuf(int fd, size_t bytes_max, size_t method, const unsigned char *old,
size_t i;
ssize_t r;
+ switch (method) {
#ifdef BUILTIN_DECOMPRESS
- /* FIXME: This doesn't cope with bzip2 */
- if (method == 2)
+ case METH_FROZEN:
return uncompressgzipped(old, newch, bytes_max, n);
- if (compr[method].maglen == 0)
+ case METH_ZLIB:
return uncompresszlib(old, newch, bytes_max, n, 1);
#endif
+#ifdef BUILTIN_BZLIB
+ case METH_BZIP:
+ return uncompressbzlib(old, newch, bytes_max, n);
+#endif
+#ifdef BUILTIN_XZLIB
+ case METH_XZ:
+ case METH_LZMA:
+ return uncompressxzlib(old, newch, bytes_max, n);
+#endif
+ default:
+ break;
+ }
+
(void)fflush(stdout);
(void)fflush(stderr);
diff --git a/src/encoding.c b/src/encoding.c
index 76244f87f95b..c3f3343150b3 100644
--- a/src/encoding.c
+++ b/src/encoding.c
@@ -35,12 +35,11 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: encoding.c,v 1.20 2019/04/15 16:48:41 christos Exp $")
+FILE_RCSID("@(#)$File: encoding.c,v 1.21 2019/06/08 20:49:14 christos Exp $")
#endif /* lint */
#include "magic.h"
#include <string.h>
-#include <memory.h>
#include <stdlib.h>
diff --git a/src/file.c b/src/file.c
index 5b60b95f4240..89d8cfb99a13 100644
--- a/src/file.c
+++ b/src/file.c
@@ -32,7 +32,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: file.c,v 1.181 2019/03/28 20:54:03 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.184 2019/08/03 11:51:59 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -76,13 +76,7 @@ int getopt_long(int, char * const *, const char *,
# define IFLNK_L ""
#endif
-#ifdef HAVE_LIBSECCOMP
-# define SECCOMP_S "S"
-#else
-# define SECCOMP_S ""
-#endif
-
-#define FILE_FLAGS "bcCdE" IFLNK_h "ik" IFLNK_L "lNnprs" SECCOMP_S "vzZ0"
+#define FILE_FLAGS "bcCdE" IFLNK_h "ik" IFLNK_L "lNnprsSvzZ0"
#define OPTSTRING "bcCde:Ef:F:hiklLm:nNpP:rsSvzZ0"
# define USAGE \
@@ -124,6 +118,7 @@ private const struct {
{ "ascii", MAGIC_NO_CHECK_ASCII },
{ "cdf", MAGIC_NO_CHECK_CDF },
{ "compress", MAGIC_NO_CHECK_COMPRESS },
+ { "csv", MAGIC_NO_CHECK_CSV },
{ "elf", MAGIC_NO_CHECK_ELF },
{ "encoding", MAGIC_NO_CHECK_ENCODING },
{ "soft", MAGIC_NO_CHECK_SOFT },
@@ -297,11 +292,11 @@ main(int argc, char *argv[])
case 's':
flags |= MAGIC_DEVICES;
break;
-#ifdef HAVE_LIBSECCOMP
case 'S':
+#ifdef HAVE_LIBSECCOMP
sandbox = 0;
- break;
#endif
+ break;
case 'v':
if (magicfile == NULL)
magicfile = magic_getpath(magicfile, action);
@@ -309,6 +304,9 @@ main(int argc, char *argv[])
VERSION);
(void)fprintf(stdout, "magic file from %s\n",
magicfile);
+#ifdef HAVE_LIBSECCOMP
+ (void)fprintf(stdout, "seccomp support included\n");
+#endif
return 0;
case 'z':
flags |= MAGIC_COMPRESS;
diff --git a/src/file.h b/src/file.h
index 69a586ab7323..947f2089d0af 100644
--- a/src/file.h
+++ b/src/file.h
@@ -27,7 +27,7 @@
*/
/*
* file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.206 2019/05/07 02:27:11 christos Exp $
+ * @(#)$File: file.h,v 1.208 2019/06/26 20:31:31 christos Exp $
*/
#ifndef __file_h__
@@ -479,6 +479,7 @@ protected int file_ascmagic_with_encoding(struct magic_set *,
protected int file_encoding(struct magic_set *, const struct buffer *,
unichar **, size_t *, const char **, const char **, const char **);
protected int file_is_json(struct magic_set *, const struct buffer *);
+protected int file_is_csv(struct magic_set *, const struct buffer *, int);
protected int file_is_tar(struct magic_set *, const struct buffer *);
protected int file_softmagic(struct magic_set *, const struct buffer *,
uint16_t *, uint16_t *, int, int);
diff --git a/src/file_opts.h b/src/file_opts.h
index 02611ccb8a85..4f894cc551b3 100644
--- a/src/file_opts.h
+++ b/src/file_opts.h
@@ -4,7 +4,10 @@
* The first column specifies the short name, if any, or 0 if none.
* The second column specifies the long name.
* The third column specifies whether it takes a parameter.
- * The fourth column is the documentation.
+ * The fourth colums specifies whether is is marked as "default"
+ * if POSIXLY_CORRECT is defined: 1,
+ * if POSIXLY_CORRECT is not defined: 2.
+ * The fifth column is the documentation.
*
* N.B. The long options' order must correspond to the code in file.c,
* and OPTSTRING must be kept up-to-date with the short options.
@@ -54,8 +57,6 @@ OPT('P', "parameter", 1, 0, " set file engine parameter limits\n"
OPT('r', "raw", 0, 0, " don't translate unprintable chars to \\ooo\n")
OPT('s', "special-files", 0, 0, " treat special (block/char devices) files as\n"
" ordinary ones\n")
-#ifdef HAVE_LIBSECCOMP
OPT('S', "no-sandbox", 0, 0, " disable system call sandboxing\n")
-#endif
OPT('C', "compile", 0, 0, " compile file specified by -m\n")
OPT('d', "debug", 0, 0, " print debugging messages\n")
diff --git a/src/fsmagic.c b/src/fsmagic.c
index 25c4f811567f..5204f20d0cdb 100644
--- a/src/fsmagic.c
+++ b/src/fsmagic.c
@@ -32,7 +32,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: fsmagic.c,v 1.80 2019/04/23 18:59:27 christos Exp $")
+FILE_RCSID("@(#)$File: fsmagic.c,v 1.81 2019/07/16 13:30:32 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -425,5 +425,11 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
if (file_printf(ms, " ") == -1)
return -1;
}
+ /*
+ * If we were looking for extensions or apple (silent) it is not our
+ * job to print here, so don't count this as a match.
+ */
+ if (ret == 1 && silent)
+ return 0;
return ret;
}
diff --git a/src/funcs.c b/src/funcs.c
index 23e7f32e63d2..9cdec0182661 100644
--- a/src/funcs.c
+++ b/src/funcs.c
@@ -27,7 +27,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.104 2019/05/07 02:27:11 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.108 2019/11/09 00:35:46 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -283,6 +283,17 @@ file_buffer(struct magic_set *ms, int fd, struct stat *st,
}
}
+ /* Check if we have a CSV file */
+ if ((ms->flags & MAGIC_NO_CHECK_CSV) == 0) {
+ m = file_is_csv(ms, &b, looks_text);
+ if ((ms->flags & MAGIC_DEBUG) != 0)
+ (void)fprintf(stderr, "[try csv %d]\n", m);
+ if (m) {
+ if (checkdone(ms, &rv))
+ goto done;
+ }
+ }
+
/* Check if we have a CDF file */
if ((ms->flags & MAGIC_NO_CHECK_CDF) == 0) {
m = file_trycdf(ms, &b);
@@ -545,7 +556,11 @@ file_regcomp(file_regex_t *rx, const char *pat, int flags)
rx->old_lc_ctype = uselocale(rx->c_lc_ctype);
assert(rx->old_lc_ctype != NULL);
#else
- rx->old_lc_ctype = setlocale(LC_CTYPE, "C");
+ rx->old_lc_ctype = setlocale(LC_CTYPE, NULL);
+ assert(rx->old_lc_ctype != NULL);
+ rx->old_lc_ctype = strdup(rx->old_lc_ctype);
+ assert(rx->old_lc_ctype != NULL);
+ (void)setlocale(LC_CTYPE, "C");
#endif
rx->pat = pat;
@@ -558,7 +573,8 @@ file_regexec(file_regex_t *rx, const char *str, size_t nmatch,
{
assert(rx->rc == 0);
/* XXX: force initialization because glibc does not always do this */
- memset(pmatch, 0, nmatch * sizeof(*pmatch));
+ if (nmatch != 0)
+ memset(pmatch, 0, nmatch * sizeof(*pmatch));
return regexec(&rx->rx, str, nmatch, pmatch, eflags);
}
@@ -572,6 +588,7 @@ file_regfree(file_regex_t *rx)
freelocale(rx->c_lc_ctype);
#else
(void)setlocale(LC_CTYPE, rx->old_lc_ctype);
+ free(rx->old_lc_ctype);
#endif
}
diff --git a/src/is_csv.c b/src/is_csv.c
new file mode 100644
index 000000000000..0081088c80ec
--- /dev/null
+++ b/src/is_csv.c
@@ -0,0 +1,197 @@
+/*-
+ * Copyright (c) 2019 Christos Zoulas
+ * 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, 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+/*
+ * Parse CSV object serialization format (RFC-4180, RFC-7111)
+ */
+
+#ifndef TEST
+#include "file.h"
+
+#ifndef lint
+FILE_RCSID("@(#)$File: is_csv.c,v 1.4 2019/06/26 20:31:31 christos Exp $")
+#endif
+
+#include <string.h>
+#include "magic.h"
+#else
+#include <sys/types.h>
+#endif
+
+
+#ifdef DEBUG
+#include <stdio.h>
+#define DPRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
+#else
+#define DPRINTF(fmt, ...)
+#endif
+
+/*
+ * if CSV_LINES == 0:
+ * check all the lines in the buffer
+ * otherwise:
+ * check only up-to the number of lines specified
+ *
+ * the last line count is always ignored if it does not end in CRLF
+ */
+#ifndef CSV_LINES
+#define CSV_LINES 10
+#endif
+
+static int csv_parse(const unsigned char *, const unsigned char *);
+
+static const unsigned char *
+eatquote(const unsigned char *uc, const unsigned char *ue)
+{
+ int quote = 0;
+
+ while (uc < ue) {
+ unsigned char c = *uc++;
+ if (c != '"') {
+ // We already got one, done.
+ if (quote) {
+ return --uc;
+ }
+ continue;
+ }
+ if (quote) {
+ // quote-quote escapes
+ quote = 0;
+ continue;
+ }
+ // first quote
+ quote = 1;
+ }
+ return ue;
+}
+
+static int
+csv_parse(const unsigned char *uc, const unsigned char *ue)
+{
+ size_t nf = 0, tf = 0, nl = 0;
+
+ while (uc < ue) {
+ unsigned char c;
+ switch (c = *uc++) {
+ case '"':
+ // Eat until the matching quote
+ uc = eatquote(uc, ue);
+ break;
+ case ',':
+ nf++;
+ break;
+ case '\n':
+ DPRINTF("%zu %zu %zu\n", nl, nf, tf);
+ nl++;
+#if CSV_LINES
+ if (nl == CSV_LINES)
+ return tf != 0 && tf == nf;
+#endif
+ if (tf == 0) {
+ // First time and no fields, give up
+ if (nf == 0)
+ return 0;
+ // First time, set the number of fields
+ tf = nf;
+ } else if (tf != nf) {
+ // Field number mismatch, we are done.
+ return 0;
+ }
+ nf = 0;
+ break;
+ default:
+ break;
+ }
+ }
+ return tf && nl > 2;
+}
+
+#ifndef TEST
+int
+file_is_csv(struct magic_set *ms, const struct buffer *b, int looks_text)
+{
+ const unsigned char *uc = CAST(const unsigned char *, b->fbuf);
+ const unsigned char *ue = uc + b->flen;
+ int mime = ms->flags & MAGIC_MIME;
+
+ if (!looks_text)
+ return 0;
+
+ if ((ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION)) != 0)
+ return 0;
+
+ if (!csv_parse(uc, ue))
+ return 0;
+
+ if (mime == MAGIC_MIME_ENCODING)
+ return 1;
+
+ if (mime) {
+ if (file_printf(ms, "application/csv") == -1)
+ return -1;
+ return 1;
+ }
+
+ if (file_printf(ms, "CSV text") == -1)
+ return -1;
+
+ return 1;
+}
+
+#else
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <err.h>
+
+int
+main(int argc, char *argv[])
+{
+ int fd, rv;
+ struct stat st;
+ unsigned char *p;
+
+ if ((fd = open(argv[1], O_RDONLY)) == -1)
+ err(EXIT_FAILURE, "Can't open `%s'", argv[1]);
+
+ if (fstat(fd, &st) == -1)
+ err(EXIT_FAILURE, "Can't stat `%s'", argv[1]);
+
+ if ((p = malloc(st.st_size)) == NULL)
+ err(EXIT_FAILURE, "Can't allocate %jd bytes",
+ (intmax_t)st.st_size);
+ if (read(fd, p, st.st_size) != st.st_size)
+ err(EXIT_FAILURE, "Can't read %jd bytes",
+ (intmax_t)st.st_size);
+ printf("is csv %d\n", csv_parse(p, p + st.st_size));
+ return 0;
+}
+#endif
diff --git a/src/magic.h.in b/src/magic.h.in
index 0580fa21ccea..d189a73c248e 100644
--- a/src/magic.h.in
+++ b/src/magic.h.in
@@ -56,6 +56,7 @@
#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_CSV 0x0080000 /* Don't check for CSV files */
#define MAGIC_NO_CHECK_TOKENS 0x0100000 /* Don't check tokens */
#define MAGIC_NO_CHECK_ENCODING 0x0200000 /* Don't check text encodings */
#define MAGIC_NO_CHECK_JSON 0x0400000 /* Don't check for JSON files */
@@ -68,6 +69,7 @@
MAGIC_NO_CHECK_APPTYPE | \
MAGIC_NO_CHECK_ELF | \
MAGIC_NO_CHECK_TEXT | \
+ MAGIC_NO_CHECK_CSV | \
MAGIC_NO_CHECK_CDF | \
MAGIC_NO_CHECK_TOKENS | \
MAGIC_NO_CHECK_ENCODING | \
diff --git a/src/readcdf.c b/src/readcdf.c
index e6ea8e47fb6b..7622c7b08aaa 100644
--- a/src/readcdf.c
+++ b/src/readcdf.c
@@ -26,7 +26,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: readcdf.c,v 1.73 2019/03/12 20:43:05 christos Exp $")
+FILE_RCSID("@(#)$File: readcdf.c,v 1.74 2019/09/11 15:46:30 christos Exp $")
#endif
#include <assert.h>
@@ -120,7 +120,11 @@ cdf_app_to_mime(const char *vbuf, const struct nv *nv)
old_lc_ctype = uselocale(c_lc_ctype);
assert(old_lc_ctype != NULL);
#else
- char *old_lc_ctype = setlocale(LC_CTYPE, "C");
+ char *old_lc_ctype = setlocale(LC_CTYPE, NULL);
+ assert(old_lc_ctype != NULL);
+ old_lc_ctype = strdup(old_lc_ctype);
+ assert(old_lc_ctype != NULL);
+ (void)setlocale(LC_CTYPE, "C");
#endif
for (i = 0; nv[i].pattern != NULL; i++)
if (strcasestr(vbuf, nv[i].pattern) != NULL) {
@@ -134,7 +138,8 @@ cdf_app_to_mime(const char *vbuf, const struct nv *nv)
(void)uselocale(old_lc_ctype);
freelocale(c_lc_ctype);
#else
- setlocale(LC_CTYPE, old_lc_ctype);
+ (void)setlocale(LC_CTYPE, old_lc_ctype);
+ free(old_lc_ctype);
#endif
return rv;
}
diff --git a/src/readelf.c b/src/readelf.c
index ef61d4cd600f..40bcfab11dca 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -27,7 +27,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.165 2019/05/07 02:27:11 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.168 2019/12/16 03:49:19 christos Exp $")
#endif
#ifdef BUILTIN_ELF
@@ -1140,6 +1140,9 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
*/
return xnh_sizeof + offset;
}
+ /*XXX: GCC */
+ memset(&nh32, 0, sizeof(nh32));
+ memset(&nh64, 0, sizeof(nh64));
memcpy(xnh_addr, &nbuf[offset], xnh_sizeof);
offset += xnh_sizeof;
@@ -1345,6 +1348,13 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
}
name_off = xsh_offset;
+ if (fsize != SIZE_UNKNOWN && fsize < name_off) {
+ if (file_printf(ms, ", too large section header offset %td",
+ name_off) == -1)
+ return -1;
+ return 0;
+ }
+
for ( ; num; num--) {
/* Read the name of this section. */
if ((namesize = pread(fd, name, sizeof(name) - 1,
@@ -1628,7 +1638,6 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
/* Things we can determine before we seek */
switch (xph_type) {
case PT_DYNAMIC:
- linking_style = "dynamically";
doread = 1;
break;
case PT_NOTE:
@@ -1644,6 +1653,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
}
/*FALLTHROUGH*/
case PT_INTERP:
+ linking_style = "dynamically";
doread = 1;
break;
default:
diff --git a/src/seccomp.c b/src/seccomp.c
index 1b9d9b855937..902a3eba7862 100644
--- a/src/seccomp.c
+++ b/src/seccomp.c
@@ -27,12 +27,13 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: seccomp.c,v 1.8 2019/02/24 18:12:04 christos Exp $")
+FILE_RCSID("@(#)$File: seccomp.c,v 1.11 2019/07/18 20:32:06 christos Exp $")
#endif /* lint */
#if HAVE_LIBSECCOMP
#include <seccomp.h> /* libseccomp */
#include <sys/prctl.h> /* prctl */
+#include <sys/ioctl.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <stdlib.h>
@@ -49,8 +50,14 @@ FILE_RCSID("@(#)$File: seccomp.c,v 1.8 2019/02/24 18:12:04 christos Exp $")
goto out; \
while (/*CONSTCOND*/0)
-static scmp_filter_ctx ctx;
+#define ALLOW_IOCTL_RULE(param) \
+ do \
+ if (seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(ioctl), 1, \
+ SCMP_CMP(1, SCMP_CMP_EQ, param)) == -1) \
+ goto out; \
+ while (/*CONSTCOND*/0)
+static scmp_filter_ctx ctx;
int
enable_sandbox_basic(void)
@@ -167,11 +174,21 @@ enable_sandbox_full(void)
ALLOW_RULE(fcntl64);
ALLOW_RULE(fstat);
ALLOW_RULE(fstat64);
+#ifdef XZLIBSUPPORT
+ ALLOW_RULE(futex);
+#endif
ALLOW_RULE(getdents);
#ifdef __NR_getdents64
ALLOW_RULE(getdents64);
#endif
- ALLOW_RULE(ioctl);
+#ifdef FIONREAD
+ // called in src/compress.c under sread
+ ALLOW_IOCTL_RULE(FIONREAD);
+#endif
+#ifdef TIOCGWINSZ
+ // musl libc may call ioctl TIOCGWINSZ when calling stdout
+ ALLOW_IOCTL_RULE(TIOCGWINSZ);
+#endif
ALLOW_RULE(lseek);
ALLOW_RULE(_llseek);
ALLOW_RULE(lstat);
@@ -197,6 +214,7 @@ enable_sandbox_full(void)
ALLOW_RULE(stat);
ALLOW_RULE(stat64);
ALLOW_RULE(sysinfo);
+ ALLOW_RULE(umask); // Used in file_pipe2file()
ALLOW_RULE(unlink);
ALLOW_RULE(write);
diff --git a/src/vasprintf.c b/src/vasprintf.c
index c87465bd5348..49d33d4a4ac2 100644
--- a/src/vasprintf.c
+++ b/src/vasprintf.c
@@ -96,7 +96,7 @@ the buffer can have a shorter length. But what? If you really need to write
HUGE string, don't use printf!
During the process, some other memory is allocated (1024 bytes minimum)
to handle the output of partial sprintf() calls. If you have only 10000 bytes
-free in memory, you *may* not be able to nprintf() a 8000 bytes-long text.
+free in memory, you *may* not be able to nprintf() an 8000 bytes-long text.
note: if a buffer overflow occurs, exit() is called. This situation should
never appear ... but if you want to be *really* sure, you have to modify the
@@ -108,7 +108,7 @@ you use strange formats.
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: vasprintf.c,v 1.16 2018/10/01 18:45:39 christos Exp $")
+FILE_RCSID("@(#)$File: vasprintf.c,v 1.17 2019/11/15 21:03:14 christos Exp $")
#endif /* lint */
#include <assert.h>