Module Name: src
Committed By: christos
Date: Mon Jun 15 00:37:25 UTC 2020
Modified Files:
src/external/bsd/file/dist: ChangeLog Makefile.am Makefile.in configure
configure.ac
src/external/bsd/file/dist/doc: file.1 magic.5
src/external/bsd/file/dist/magic: Makefile.am Makefile.in
src/external/bsd/file/dist/magic/magdir: archive elf filesystems parix
pgp
src/external/bsd/file/dist/src: apprentice.c compress.c der.c file.c
file.h funcs.c is_csv.c is_json.c magic.c print.c readelf.c
softmagic.c
src/external/bsd/file/include: config.h
src/external/bsd/file/lib: shlib_version
Log Message:
merge conflicts
To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/external/bsd/file/dist/ChangeLog
cvs rdiff -u -r1.3 -r1.4 src/external/bsd/file/dist/Makefile.am
cvs rdiff -u -r1.18 -r1.19 src/external/bsd/file/dist/Makefile.in \
src/external/bsd/file/dist/configure.ac
cvs rdiff -u -r1.22 -r1.23 src/external/bsd/file/dist/configure
cvs rdiff -u -r1.24 -r1.25 src/external/bsd/file/dist/doc/file.1
cvs rdiff -u -r1.21 -r1.22 src/external/bsd/file/dist/doc/magic.5
cvs rdiff -u -r1.18 -r1.19 src/external/bsd/file/dist/magic/Makefile.am
cvs rdiff -u -r1.21 -r1.22 src/external/bsd/file/dist/magic/Makefile.in
cvs rdiff -u -r1.17 -r1.18 src/external/bsd/file/dist/magic/magdir/archive
cvs rdiff -u -r1.18 -r1.19 src/external/bsd/file/dist/magic/magdir/elf
cvs rdiff -u -r1.16 -r1.17 \
src/external/bsd/file/dist/magic/magdir/filesystems
cvs rdiff -u -r1.2 -r1.3 src/external/bsd/file/dist/magic/magdir/parix
cvs rdiff -u -r1.7 -r1.8 src/external/bsd/file/dist/magic/magdir/pgp
cvs rdiff -u -r1.24 -r1.25 src/external/bsd/file/dist/src/apprentice.c \
src/external/bsd/file/dist/src/file.h
cvs rdiff -u -r1.19 -r1.20 src/external/bsd/file/dist/src/compress.c
cvs rdiff -u -r1.5 -r1.6 src/external/bsd/file/dist/src/der.c
cvs rdiff -u -r1.14 -r1.15 src/external/bsd/file/dist/src/file.c \
src/external/bsd/file/dist/src/magic.c \
src/external/bsd/file/dist/src/print.c
cvs rdiff -u -r1.17 -r1.18 src/external/bsd/file/dist/src/funcs.c
cvs rdiff -u -r1.1.1.1 -r1.2 src/external/bsd/file/dist/src/is_csv.c
cvs rdiff -u -r1.3 -r1.4 src/external/bsd/file/dist/src/is_json.c
cvs rdiff -u -r1.23 -r1.24 src/external/bsd/file/dist/src/readelf.c
cvs rdiff -u -r1.22 -r1.23 src/external/bsd/file/dist/src/softmagic.c
cvs rdiff -u -r1.15 -r1.16 src/external/bsd/file/include/config.h
cvs rdiff -u -r1.7 -r1.8 src/external/bsd/file/lib/shlib_version
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/external/bsd/file/dist/ChangeLog
diff -u src/external/bsd/file/dist/ChangeLog:1.10 src/external/bsd/file/dist/ChangeLog:1.11
--- src/external/bsd/file/dist/ChangeLog:1.10 Mon Dec 16 21:31:05 2019
+++ src/external/bsd/file/dist/ChangeLog Sun Jun 14 20:37:24 2020
@@ -1,3 +1,83 @@
+2020-06-14 20:02 Christos Zoulas <[email protected]>
+
+ * release 5.39
+
+2020-06-07 20:00 Christos Zoulas <[email protected]>
+
+ * Remove unused subtype_mime (Steve Grubb)
+ * Remove unused check in okstat (Steve Grubb)
+ * Fix mime-type in elf binaries by making sure $x is set
+ * Fix indirect negative offsets broken by OFFNEGATIVE
+ * Fix GUID equality check
+ * PR/165: Handle empty array and strings in JSON
+ * PR/162: Add --exclude-quiet
+
+2020-06-06 15:33 Christos Zoulas <[email protected]>
+
+ * Fix memory leak in ascmagic (Steve Grubb)
+
+2020-06-04 00:21 Christos Zoulas <[email protected]>
+
+ * Fix string comparison length with ignore whitespace
+
+2020-05-31 00:11 Christos Zoulas <[email protected]>
+
+ * Fix mingwin 64 compilation
+
+2020-05-30 23:56 Christos Zoulas <[email protected]>
+
+ * PR/159: whitelist getpid needed for file_pipe2file()
+
+2020-05-09 18:57 Christos Zoulas <[email protected]>
+
+ * Indicate negative offsets with a flag OFFNEGATIVE
+ so that -0 works.
+ * Introduce "offset" magic type that can be used to
+ detect the file size, and bail on short files.
+ * document DER better in the magic man page.
+
+2020-03-11 21:53 Christos Zoulas <[email protected]>
+
+ * fix memory leaks (SonarQube)
+
+2020-03-08 21:33 Christos Zoulas <[email protected]>
+
+ * fix memory leaks (SonarQube)
+ * rewrite confusing loops (SonarQube)
+ * fix bogus test (SonarQube)
+ * pass a sized buffer to file_fmttime() (SonarQube)
+
+ * fix memory leaks (SonarQube)
+
+2020-02-20 15:50 Christos Zoulas <[email protected]>
+
+ * Don't allow * in printf formats, or the code itself (Christoph Biedl)
+ * Introduce a printf output size checker to avoid DoS attacks
+
+2020-02-17 17:22 Christos Zoulas <[email protected]>
+
+ * Avoid memory leak on error (oss-fuzz)
+ * Check length of string on DER before derefercing and add new types
+ * Add missing DER string (oss-fuzz)
+
+2020-02-16 20:45 Christos Zoulas <[email protected]>
+
+ * Add missing DER types, and debugging
+
+2020-02-13 13:10 Christos Zoulas <[email protected]>
+
+ * PR/140: Avoid abort with hand-crafted magic file (gockelhahn)
+ * PR/139 Avoid DoS in printf with hand-crafted magic file (gockelhahn)
+ * PR/138: Avoid crash with hand-crafted magic file (gockelhahn)
+
+2020-02-12 17:30 Christos Zoulas <[email protected]>
+
+ * PR/136: Fix static build by adding a libmagic.pc (Fabrice Fontaine)
+
+2019-12-24 14:16 Christos Zoulas <[email protected]>
+
+ * add guid support
+
2019-12-16 21:11 Christos Zoulas <[email protected]>
* release 5.38
Index: src/external/bsd/file/dist/Makefile.am
diff -u src/external/bsd/file/dist/Makefile.am:1.3 src/external/bsd/file/dist/Makefile.am:1.4
--- src/external/bsd/file/dist/Makefile.am:1.3 Thu May 12 21:52:12 2011
+++ src/external/bsd/file/dist/Makefile.am Sun Jun 14 20:37:24 2020
@@ -2,4 +2,9 @@ ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = MAINT
-SUBDIRS = src magic doc
+SUBDIRS = src magic tests doc python
+
+# This variable must have 'exec' in its name, in order to be installed
+# by 'install-exec' target (instead of default 'install-data')
+pkgconfigexecdir = $(libdir)/pkgconfig
+pkgconfigexec_DATA = libmagic.pc
Index: src/external/bsd/file/dist/Makefile.in
diff -u src/external/bsd/file/dist/Makefile.in:1.18 src/external/bsd/file/dist/Makefile.in:1.19
--- src/external/bsd/file/dist/Makefile.in:1.18 Mon Dec 16 21:31:05 2019
+++ src/external/bsd/file/dist/Makefile.in Sun Jun 14 20:37:24 2020
@@ -13,6 +13,7 @@
# PARTICULAR PURPOSE.
@SET_MAKE@
+
VPATH = @srcdir@
am__is_gnu_make = { \
if test -z '$(MAKELEVEL)'; then \
@@ -100,7 +101,7 @@ am__CONFIG_DISTCLEAN_FILES = config.stat
configure.lineno config.status.lineno
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = config.h
-CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_FILES = libmagic.pc
CONFIG_CLEAN_VPATH_FILES =
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@@ -129,6 +130,35 @@ am__can_run_installinfo = \
n|no|NO) false;; \
*) (install-info --version) >/dev/null 2>&1;; \
esac
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+ *) f=$$p;; \
+ esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+ if (++n[$$2] == $(am__install_max)) \
+ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+ END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+ test -z "$$files" \
+ || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+ $(am__cd) "$$dir" && rm -f $$files; }; \
+ }
+am__installdirs = "$(DESTDIR)$(pkgconfigexecdir)"
+DATA = $(pkgconfigexec_DATA)
RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \
distclean-recursive maintainer-clean-recursive
am__recursive_targets = \
@@ -159,9 +189,10 @@ ETAGS = etags
CTAGS = ctags
CSCOPE = cscope
DIST_SUBDIRS = $(SUBDIRS)
-am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.h.in AUTHORS \
- COPYING ChangeLog INSTALL NEWS README TODO compile \
- config.guess config.sub install-sh ltmain.sh missing
+am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.h.in \
+ $(srcdir)/libmagic.pc.in AUTHORS COPYING ChangeLog INSTALL \
+ NEWS README TODO compile config.guess config.sub install-sh \
+ ltmain.sh missing
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
distdir = $(PACKAGE)-$(VERSION)
top_distdir = $(distdir)
@@ -328,6 +359,11 @@ top_srcdir = @top_srcdir@
ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = MAINT
SUBDIRS = src magic tests doc python
+
+# This variable must have 'exec' in its name, in order to be installed
+# by 'install-exec' target (instead of default 'install-data')
+pkgconfigexecdir = $(libdir)/pkgconfig
+pkgconfigexec_DATA = libmagic.pc
all: config.h
$(MAKE) $(AM_MAKEFLAGS) all-recursive
@@ -380,6 +416,8 @@ $(srcdir)/config.h.in: @MAINTAINER_MODE_
distclean-hdr:
-rm -f config.h stamp-h1
+libmagic.pc: $(top_builddir)/config.status $(srcdir)/libmagic.pc.in
+ cd $(top_builddir) && $(SHELL) ./config.status $@
mostlyclean-libtool:
-rm -f *.lo
@@ -389,6 +427,27 @@ clean-libtool:
distclean-libtool:
-rm -f libtool config.lt
+install-pkgconfigexecDATA: $(pkgconfigexec_DATA)
+ @$(NORMAL_INSTALL)
+ @list='$(pkgconfigexec_DATA)'; test -n "$(pkgconfigexecdir)" || list=; \
+ if test -n "$$list"; then \
+ echo " $(MKDIR_P) '$(DESTDIR)$(pkgconfigexecdir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(pkgconfigexecdir)" || exit 1; \
+ fi; \
+ for p in $$list; do \
+ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+ echo "$$d$$p"; \
+ done | $(am__base_list) | \
+ while read files; do \
+ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(pkgconfigexecdir)'"; \
+ $(INSTALL_DATA) $$files "$(DESTDIR)$(pkgconfigexecdir)" || exit $$?; \
+ done
+
+uninstall-pkgconfigexecDATA:
+ @$(NORMAL_UNINSTALL)
+ @list='$(pkgconfigexec_DATA)'; test -n "$(pkgconfigexecdir)" || list=; \
+ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ dir='$(DESTDIR)$(pkgconfigexecdir)'; $(am__uninstall_files_from_dir)
# This directory's subdirectories are mostly independent; you can cd
# into them and run 'make' without going through this Makefile.
@@ -689,9 +748,12 @@ distcleancheck: distclean
exit 1; } >&2
check-am: all-am
check: check-recursive
-all-am: Makefile config.h
+all-am: Makefile $(DATA) config.h
installdirs: installdirs-recursive
installdirs-am:
+ for dir in "$(DESTDIR)$(pkgconfigexecdir)"; do \
+ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+ done
install: install-recursive
install-exec: install-exec-recursive
install-data: install-data-recursive
@@ -750,7 +812,7 @@ install-dvi: install-dvi-recursive
install-dvi-am:
-install-exec-am:
+install-exec-am: install-pkgconfigexecDATA
install-html: install-html-recursive
@@ -790,7 +852,7 @@ ps: ps-recursive
ps-am:
-uninstall-am:
+uninstall-am: uninstall-pkgconfigexecDATA
.MAKE: $(am__recursive_targets) all install-am install-strip
@@ -804,12 +866,13 @@ uninstall-am:
info-am install install-am install-data install-data-am \
install-dvi install-dvi-am install-exec install-exec-am \
install-html install-html-am install-info install-info-am \
- install-man install-pdf install-pdf-am install-ps \
- install-ps-am install-strip installcheck installcheck-am \
- installdirs installdirs-am maintainer-clean \
- maintainer-clean-generic mostlyclean mostlyclean-generic \
- mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \
- uninstall-am
+ install-man install-pdf install-pdf-am \
+ install-pkgconfigexecDATA install-ps install-ps-am \
+ install-strip installcheck installcheck-am installdirs \
+ installdirs-am maintainer-clean maintainer-clean-generic \
+ mostlyclean mostlyclean-generic mostlyclean-libtool pdf pdf-am \
+ ps ps-am tags tags-am uninstall uninstall-am \
+ uninstall-pkgconfigexecDATA
.PRECIOUS: Makefile
Index: src/external/bsd/file/dist/configure.ac
diff -u src/external/bsd/file/dist/configure.ac:1.18 src/external/bsd/file/dist/configure.ac:1.19
--- src/external/bsd/file/dist/configure.ac:1.18 Mon Dec 16 21:31:05 2019
+++ src/external/bsd/file/dist/configure.ac Sun Jun 14 20:37:24 2020
@@ -1,5 +1,5 @@
dnl Process this file with autoconf to produce a configure script.
-AC_INIT([file],[5.38],[[email protected]])
+AC_INIT([file],[5.39],[[email protected]])
AM_INIT_AUTOMAKE([subdir-objects foreign])
AM_MAINTAINER_MODE(disable)
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
@@ -218,5 +218,5 @@ if test "$ac_cv_header_lzma_h$ac_cv_lib
AC_DEFINE([XZLIBSUPPORT], 1, [Enable xzlib compression support])
fi
-AC_CONFIG_FILES([Makefile src/Makefile magic/Makefile tests/Makefile doc/Makefile python/Makefile])
+AC_CONFIG_FILES([Makefile src/Makefile magic/Makefile tests/Makefile doc/Makefile python/Makefile libmagic.pc])
AC_OUTPUT
Index: src/external/bsd/file/dist/configure
diff -u src/external/bsd/file/dist/configure:1.22 src/external/bsd/file/dist/configure:1.23
--- src/external/bsd/file/dist/configure:1.22 Mon Dec 16 21:31:05 2019
+++ src/external/bsd/file/dist/configure Sun Jun 14 20:37:24 2020
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for file 5.38.
+# Generated by GNU Autoconf 2.69 for file 5.39.
#
# Report bugs to <[email protected]>.
#
@@ -590,8 +590,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='file'
PACKAGE_TARNAME='file'
-PACKAGE_VERSION='5.38'
-PACKAGE_STRING='file 5.38'
+PACKAGE_VERSION='5.39'
+PACKAGE_STRING='file 5.39'
PACKAGE_BUGREPORT='[email protected]'
PACKAGE_URL=''
@@ -1338,7 +1338,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.38 to adapt to many kinds of systems.
+\`configure' configures file 5.39 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1408,7 +1408,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of file 5.38:";;
+ short | recursive ) echo "Configuration of file 5.39:";;
esac
cat <<\_ACEOF
@@ -1531,7 +1531,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-file configure 5.38
+file configure 5.39
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
@@ -2187,7 +2187,7 @@ 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.38, which was
+It was created by file $as_me 5.39, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
@@ -3075,7 +3075,7 @@ fi
# Define the identity of the package.
PACKAGE='file'
- VERSION='5.38'
+ VERSION='5.39'
cat >>confdefs.h <<_ACEOF
@@ -15196,7 +15196,7 @@ $as_echo "#define XZLIBSUPPORT 1" >>conf
fi
-ac_config_files="$ac_config_files Makefile src/Makefile magic/Makefile tests/Makefile doc/Makefile python/Makefile"
+ac_config_files="$ac_config_files Makefile src/Makefile magic/Makefile tests/Makefile doc/Makefile python/Makefile libmagic.pc"
cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
@@ -15745,7 +15745,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_wri
# 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.38, which was
+This file was extended by file $as_me 5.39, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -15811,7 +15811,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
-file config.status 5.38
+file config.status 5.39
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
@@ -16232,6 +16232,7 @@ do
"tests/Makefile") CONFIG_FILES="$CONFIG_FILES tests/Makefile" ;;
"doc/Makefile") CONFIG_FILES="$CONFIG_FILES doc/Makefile" ;;
"python/Makefile") CONFIG_FILES="$CONFIG_FILES python/Makefile" ;;
+ "libmagic.pc") CONFIG_FILES="$CONFIG_FILES libmagic.pc" ;;
*) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
esac
Index: src/external/bsd/file/dist/doc/file.1
diff -u src/external/bsd/file/dist/doc/file.1:1.24 src/external/bsd/file/dist/doc/file.1:1.25
--- src/external/bsd/file/dist/doc/file.1:1.24 Mon Dec 16 21:31:05 2019
+++ src/external/bsd/file/dist/doc/file.1 Sun Jun 14 20:37:24 2020
@@ -1,7 +1,7 @@
-.\" $NetBSD: file.1,v 1.24 2019/12/17 02:31:05 christos Exp $
+.\" $NetBSD: file.1,v 1.25 2020/06/15 00:37:24 christos Exp $
.\"
-.\" $File: file.man,v 1.138 2019/10/15 18:00:40 christos Exp $
-.Dd July 13, 2019
+.\" $File: file.man,v 1.140 2020/06/07 17:41:07 christos Exp $
+.Dd June 7, 2020
.Dt FILE 1
.Os
.Sh NAME
@@ -12,6 +12,7 @@
.Bk -words
.Op Fl bcdEhiklLNnprsSvzZ0
.Op Fl Fl apple
+.Op Fl Fl exclude-quiet
.Op Fl Fl extension
.Op Fl Fl mime-encoding
.Op Fl Fl mime-type
@@ -28,7 +29,7 @@
.Nm
.Op Fl Fl help
.Sh DESCRIPTION
-This manual page documents version 5.38 of the
+This manual page documents version 5.39 of the
.Nm
command.
.Pp
@@ -231,6 +232,14 @@ the soft magic method.
A synonym for
.Sq ascii .
.El
+.It Fl Fl exclude-quiet
+Like
+.Fl Fl exclude
+but ignore tests that
+.Nm
+does not know about.
+This is intended for compatilibity with older versions of
+.Nm .
.It Fl Fl extension
Print a slash-separated list of valid extensions for the file type found.
.It Fl F , Fl Fl separator Ar separator
@@ -328,13 +337,13 @@ never read them.
Set various parameter limits.
.Bl -column "elf_phnum" "Default" "XXXXXXXXXXXXXXXXXXXXXXXXXXX" -offset indent
.It Sy "Name" Ta Sy "Default" Ta Sy "Explanation"
-.It Li indir Ta 15 Ta recursion limit for indirect magic
-.It Li name Ta 30 Ta use count limit for name/use magic
+.It Li bytes Ta 1048576 Ta max number of bytes to read from file
.It Li elf_notes Ta 256 Ta max ELF notes processed
-.It Li elf_phnum Ta 128 Ta max ELF program sections processed
+.It Li elf_phnum Ta 2048 Ta max ELF program sections processed
.It Li elf_shnum Ta 32768 Ta max ELF sections processed
+.It Li indir Ta 50 Ta recursion limit for indirect magic
+.It Li name Ta 50 Ta use count limit for name/use magic
.It Li regex Ta 8192 Ta length limit for regex searches
-.It Li bytes Ta 1048576 Ta max number of bytes to read from file
.El
.It Fl r , Fl Fl raw
Don't translate unprintable characters to \eooo.
Index: src/external/bsd/file/dist/doc/magic.5
diff -u src/external/bsd/file/dist/doc/magic.5:1.21 src/external/bsd/file/dist/doc/magic.5:1.22
--- src/external/bsd/file/dist/doc/magic.5:1.21 Mon Dec 16 21:31:05 2019
+++ src/external/bsd/file/dist/doc/magic.5 Sun Jun 14 20:37:24 2020
@@ -1,7 +1,7 @@
-.\" $NetBSD: magic.5,v 1.21 2019/12/17 02:31:05 christos Exp $
+.\" $NetBSD: magic.5,v 1.22 2020/06/15 00:37:24 christos Exp $
.\"
-.\" $File: magic.man,v 1.97 2019/11/15 21:03:14 christos Exp $
-.Dd January 21, 2019
+.\" $File: magic.man,v 1.98 2020/05/09 18:55:23 christos Exp $
+.Dd May 9, 2020
.Dt MAGIC 5
.Os
.\" install as magic.4 on USG, magic.5 on V7, Berkeley and Linux systems.
@@ -12,7 +12,7 @@
This manual page documents the format of magic files as
used by the
.Xr file 1
-command, version 5.38.
+command, version 5.39.
The
.Xr file 1
command identifies the type of a file using,
@@ -302,6 +302,62 @@ This test is always true and clears the
It is intended to be used with the
.Dv default
test.
+.It Dv der
+Parse the file as a DER Certificate file.
+The test field is used as a der type that needs to be matched.
+The DER types are:
+.Dv eoc ,
+.Dv bool ,
+.Dv int ,
+.Dv bit_str ,
+.Dv octet_str ,
+.Dv null ,
+.Dv obj_id ,
+.Dv obj_desc ,
+.Dv ext ,
+.Dv real ,
+.Dv enum ,
+.Dv embed ,
+.Dv utf8_str ,
+.Dv rel_oid ,
+.Dv time ,
+.Dv res2 ,
+.Dv seq ,
+.Dv set ,
+.Dv num_str ,
+.Dv prt_str ,
+.Dv t61_str ,
+.Dv vid_str ,
+.Dv ia5_str ,
+.Dv utc_time ,
+.Dv gen_time ,
+.Dv gr_str ,
+.Dv vis_str ,
+.Dv gen_str ,
+.Dv univ_str ,
+.Dv char_str ,
+.Dv bmp_str ,
+.Dv date ,
+.Dv tod ,
+.Dv datetime ,
+.Dv duration ,
+.Dv oid-iri ,
+.Dv rel-oid-iri .
+These types can be followed by an optional numeric size, which indicates
+the field width in bytes.
+.It Dv guid
+A Globally Unique Identifier, parsed and printed as
+XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.
+It's format is a string.
+.It Dv offset
+This is a quad value indicating the current offset of the file.
+It can be used to determine the size of the file or the magic buffer.
+For example the magic entries:
+.Bd -literal -offset indent
+-0 offset x this file is %lld bytes
+-0 offset <=100 must be more than 100 \e
+ bytes and is only %lld
+.Ed
.El
.Pp
For compatibility with the Single
Index: src/external/bsd/file/dist/magic/Makefile.am
diff -u src/external/bsd/file/dist/magic/Makefile.am:1.18 src/external/bsd/file/dist/magic/Makefile.am:1.19
--- src/external/bsd/file/dist/magic/Makefile.am:1.18 Mon Dec 16 21:31:05 2019
+++ src/external/bsd/file/dist/magic/Makefile.am Sun Jun 14 20:37:24 2020
@@ -1,5 +1,5 @@
#
-# $File: Makefile.am,v 1.151 2019/11/02 18:37:58 christos Exp $
+# $File: Makefile.am,v 1.157 2020/05/21 16:22:47 christos Exp $
#
MAGIC_FRAGMENT_BASE = magdir
MAGIC_DIR = $(top_srcdir)/magic
@@ -28,6 +28,7 @@ $(MAGIC_FRAGMENT_DIR)/application \
$(MAGIC_FRAGMENT_DIR)/applix \
$(MAGIC_FRAGMENT_DIR)/apt \
$(MAGIC_FRAGMENT_DIR)/archive \
+$(MAGIC_FRAGMENT_DIR)/asf \
$(MAGIC_FRAGMENT_DIR)/assembler \
$(MAGIC_FRAGMENT_DIR)/asterix \
$(MAGIC_FRAGMENT_DIR)/att3b \
@@ -78,6 +79,7 @@ $(MAGIC_FRAGMENT_DIR)/dataone \
$(MAGIC_FRAGMENT_DIR)/dbpf \
$(MAGIC_FRAGMENT_DIR)/der \
$(MAGIC_FRAGMENT_DIR)/diamond \
+$(MAGIC_FRAGMENT_DIR)/dif \
$(MAGIC_FRAGMENT_DIR)/diff \
$(MAGIC_FRAGMENT_DIR)/digital \
$(MAGIC_FRAGMENT_DIR)/dolby \
@@ -271,6 +273,7 @@ $(MAGIC_FRAGMENT_DIR)/sql \
$(MAGIC_FRAGMENT_DIR)/ssh \
$(MAGIC_FRAGMENT_DIR)/ssl \
$(MAGIC_FRAGMENT_DIR)/sun \
+$(MAGIC_FRAGMENT_DIR)/sylk \
$(MAGIC_FRAGMENT_DIR)/symbos \
$(MAGIC_FRAGMENT_DIR)/sysex \
$(MAGIC_FRAGMENT_DIR)/tcl \
@@ -285,7 +288,9 @@ $(MAGIC_FRAGMENT_DIR)/troff \
$(MAGIC_FRAGMENT_DIR)/tuxedo \
$(MAGIC_FRAGMENT_DIR)/typeset \
$(MAGIC_FRAGMENT_DIR)/unicode \
+$(MAGIC_FRAGMENT_DIR)/unisig \
$(MAGIC_FRAGMENT_DIR)/unknown \
+$(MAGIC_FRAGMENT_DIR)/usd \
$(MAGIC_FRAGMENT_DIR)/uterus \
$(MAGIC_FRAGMENT_DIR)/uuencode \
$(MAGIC_FRAGMENT_DIR)/vacuum-cleaner \
@@ -301,6 +306,7 @@ $(MAGIC_FRAGMENT_DIR)/vmware \
$(MAGIC_FRAGMENT_DIR)/vorbis \
$(MAGIC_FRAGMENT_DIR)/vxl \
$(MAGIC_FRAGMENT_DIR)/warc \
+$(MAGIC_FRAGMENT_DIR)/web \
$(MAGIC_FRAGMENT_DIR)/weak \
$(MAGIC_FRAGMENT_DIR)/webassembly \
$(MAGIC_FRAGMENT_DIR)/windows \
Index: src/external/bsd/file/dist/magic/Makefile.in
diff -u src/external/bsd/file/dist/magic/Makefile.in:1.21 src/external/bsd/file/dist/magic/Makefile.in:1.22
--- src/external/bsd/file/dist/magic/Makefile.in:1.21 Mon Dec 16 21:31:05 2019
+++ src/external/bsd/file/dist/magic/Makefile.in Sun Jun 14 20:37:24 2020
@@ -274,7 +274,7 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
#
-# $File: Makefile.am,v 1.151 2019/11/02 18:37:58 christos Exp $
+# $File: Makefile.am,v 1.157 2020/05/21 16:22:47 christos Exp $
#
MAGIC_FRAGMENT_BASE = magdir
MAGIC_DIR = $(top_srcdir)/magic
@@ -301,6 +301,7 @@ $(MAGIC_FRAGMENT_DIR)/application \
$(MAGIC_FRAGMENT_DIR)/applix \
$(MAGIC_FRAGMENT_DIR)/apt \
$(MAGIC_FRAGMENT_DIR)/archive \
+$(MAGIC_FRAGMENT_DIR)/asf \
$(MAGIC_FRAGMENT_DIR)/assembler \
$(MAGIC_FRAGMENT_DIR)/asterix \
$(MAGIC_FRAGMENT_DIR)/att3b \
@@ -351,6 +352,7 @@ $(MAGIC_FRAGMENT_DIR)/dataone \
$(MAGIC_FRAGMENT_DIR)/dbpf \
$(MAGIC_FRAGMENT_DIR)/der \
$(MAGIC_FRAGMENT_DIR)/diamond \
+$(MAGIC_FRAGMENT_DIR)/dif \
$(MAGIC_FRAGMENT_DIR)/diff \
$(MAGIC_FRAGMENT_DIR)/digital \
$(MAGIC_FRAGMENT_DIR)/dolby \
@@ -544,6 +546,7 @@ $(MAGIC_FRAGMENT_DIR)/sql \
$(MAGIC_FRAGMENT_DIR)/ssh \
$(MAGIC_FRAGMENT_DIR)/ssl \
$(MAGIC_FRAGMENT_DIR)/sun \
+$(MAGIC_FRAGMENT_DIR)/sylk \
$(MAGIC_FRAGMENT_DIR)/symbos \
$(MAGIC_FRAGMENT_DIR)/sysex \
$(MAGIC_FRAGMENT_DIR)/tcl \
@@ -558,7 +561,9 @@ $(MAGIC_FRAGMENT_DIR)/troff \
$(MAGIC_FRAGMENT_DIR)/tuxedo \
$(MAGIC_FRAGMENT_DIR)/typeset \
$(MAGIC_FRAGMENT_DIR)/unicode \
+$(MAGIC_FRAGMENT_DIR)/unisig \
$(MAGIC_FRAGMENT_DIR)/unknown \
+$(MAGIC_FRAGMENT_DIR)/usd \
$(MAGIC_FRAGMENT_DIR)/uterus \
$(MAGIC_FRAGMENT_DIR)/uuencode \
$(MAGIC_FRAGMENT_DIR)/vacuum-cleaner \
@@ -574,6 +579,7 @@ $(MAGIC_FRAGMENT_DIR)/vmware \
$(MAGIC_FRAGMENT_DIR)/vorbis \
$(MAGIC_FRAGMENT_DIR)/vxl \
$(MAGIC_FRAGMENT_DIR)/warc \
+$(MAGIC_FRAGMENT_DIR)/web \
$(MAGIC_FRAGMENT_DIR)/weak \
$(MAGIC_FRAGMENT_DIR)/webassembly \
$(MAGIC_FRAGMENT_DIR)/windows \
Index: src/external/bsd/file/dist/magic/magdir/archive
diff -u src/external/bsd/file/dist/magic/magdir/archive:1.17 src/external/bsd/file/dist/magic/magdir/archive:1.18
--- src/external/bsd/file/dist/magic/magdir/archive:1.17 Mon Dec 16 21:31:05 2019
+++ src/external/bsd/file/dist/magic/magdir/archive Sun Jun 14 20:37:24 2020
@@ -1,5 +1,5 @@
#------------------------------------------------------------------------------
-# $File: archive,v 1.133 2019/11/15 21:03:14 christos Exp $
+# $File: archive,v 1.138 2020/06/07 23:29:26 christos Exp $
# archive: file(1) magic for archive formats (see also "msdos" for self-
# extracting compressed archives)
#
@@ -236,7 +236,8 @@
!:ext deb/udeb
>14 string -binary Debian binary package
!:mime application/vnd.debian.binary-package
-!:ext deb/udeb
+# For ipk packager see also https://en.wikipedia.org/wiki/Opkg
+!:ext deb/udeb/ipk
# This should not happen
>14 default x Unknown Debian package
# NL terminated version; for most Debian cases this is 2.0 or 2.1 for splitted
@@ -250,7 +251,16 @@
>>0 search/0x93e4f data.tar. \b, data compression
# the above line only works if FILE_BYTES_MAX in ../../src/file.h is raised
# for example like libreoffice-dev-doc_1%3a5.2.7-1+rpi1+deb9u3_all.deb
->>>&0 string x %.4s
+>>>&0 string x %.2s
+# skip space (0x20 BSD) and slash (0x2f System V) character marking end of name
+>>>&2 ubyte !0x20
+>>>>&-1 ubyte !0x2f
+# display 3rd character of file name extension like 2 of bz2 or m of lzma
+>>>>>&-1 ubyte x \b%c
+>>>>>>&0 ubyte !0x20
+>>>>>>>&-1 ubyte !0x2f
+# display 4th character of file name extension like a of lzma
+>>>>>>>>&-1 ubyte x \b%c
# splitted debian package case
>68 string =2.1\n
# dpkg-1.18.25/dpkg-split/info.c
@@ -1124,71 +1134,120 @@
# OpenOffice formats (for OpenOffice 1.x / StarOffice 6/7)
# (mimetype contains "application/vnd.sun.xml.<SUBTYPE>")
+# URL: https://en.wikipedia.org/wiki/OpenOffice.org_XML
+# reference: http://fileformats.archiveteam.org/wiki/OpenOffice.org_XML
>>50 string vnd.sun.xml. OpenOffice.org 1.x
>>>62 string writer Writer
>>>>68 byte !0x2e document
+!:mime application/vnd.sun.xml.writer
+!:ext sxw
>>>>68 string .template template
+!:mime application/vnd.sun.xml.writer.template
+!:ext stw
+>>>>68 string .web Web template
+!:mime application/vnd.sun.xml.writer.web
+!:ext stw
>>>>68 string .global global document
+!:mime application/vnd.sun.xml.writer.global
+!:ext sxg
>>>62 string calc Calc
>>>>66 byte !0x2e spreadsheet
+!:mime application/vnd.sun.xml.calc
+!:ext sxc
>>>>66 string .template template
+!:mime application/vnd.sun.xml.calc.template
+!:ext stc
>>>62 string draw Draw
>>>>66 byte !0x2e document
+!:mime application/vnd.sun.xml.draw
+!:ext sxd
>>>>66 string .template template
+!:mime application/vnd.sun.xml.draw.template
+!:ext std
>>>62 string impress Impress
>>>>69 byte !0x2e presentation
+!:mime application/vnd.sun.xml.impress
+!:ext sxi
>>>>69 string .template template
+!:mime application/vnd.sun.xml.impress.template
+!:ext sti
>>>62 string math Math document
+!:mime application/vnd.sun.xml.math
+!:ext sxm
>>>62 string base Database file
+!:mime application/vnd.sun.xml.base
+!:ext sdb
# OpenDocument formats (for OpenOffice 2.x / StarOffice >= 8)
+# URL: http://fileformats.archiveteam.org/wiki/OpenDocument
# https://lists.oasis-open.org/archives/office/200505/msg00006.html
# (mimetype contains "application/vnd.oasis.opendocument.<SUBTYPE>")
>>50 string vnd.oasis.opendocument. OpenDocument
>>>73 string text
>>>>77 byte !0x2d Text
!:mime application/vnd.oasis.opendocument.text
+!:ext odt
>>>>77 string -template Text Template
!:mime application/vnd.oasis.opendocument.text-template
+!:ext ott
>>>>77 string -web HTML Document Template
!:mime application/vnd.oasis.opendocument.text-web
+!:ext oth
>>>>77 string -master Master Document
!:mime application/vnd.oasis.opendocument.text-master
+!:ext odm
>>>73 string graphics
>>>>81 byte !0x2d Drawing
!:mime application/vnd.oasis.opendocument.graphics
->>>>81 string -template Template
+!:ext odg
+>>>>81 string -template Drawing Template
!:mime application/vnd.oasis.opendocument.graphics-template
+!:ext otg
>>>73 string presentation
>>>>85 byte !0x2d Presentation
!:mime application/vnd.oasis.opendocument.presentation
->>>>85 string -template Template
+!:ext odp
+>>>>85 string -template Presentation Template
!:mime application/vnd.oasis.opendocument.presentation-template
+!:ext otp
>>>73 string spreadsheet
>>>>84 byte !0x2d Spreadsheet
!:mime application/vnd.oasis.opendocument.spreadsheet
->>>>84 string -template Template
+!:ext ods
+>>>>84 string -template Spreadsheet Template
!:mime application/vnd.oasis.opendocument.spreadsheet-template
+!:ext ots
>>>73 string chart
>>>>78 byte !0x2d Chart
!:mime application/vnd.oasis.opendocument.chart
->>>>78 string -template Template
+!:ext odc
+>>>>78 string -template Chart Template
!:mime application/vnd.oasis.opendocument.chart-template
+!:ext otc
>>>73 string formula
>>>>80 byte !0x2d Formula
!:mime application/vnd.oasis.opendocument.formula
->>>>80 string -template Template
+!:ext odf
+>>>>80 string -template Formula Template
!:mime application/vnd.oasis.opendocument.formula-template
+!:ext otf
+# https://www.loc.gov/preservation/digital/formats/fdd/fdd000441.shtml
>>>73 string database Database
!:mime application/vnd.oasis.opendocument.database
+!:ext odb
# Valid for LibreOffice Base 6.0.1.1 at least
>>>73 string base Database
-!:mime application/vnd.oasis.opendocument.base
+# https://bugs.documentfoundation.org/show_bug.cgi?id=45854
+!:mime application/vnd.oasis.opendocument.database
+#!:mime application/vnd.oasis.opendocument.base
+!:ext odb
>>>73 string image
>>>>78 byte !0x2d Image
!:mime application/vnd.oasis.opendocument.image
->>>>78 string -template Template
+!:ext odi
+>>>>78 string -template Image Template
!:mime application/vnd.oasis.opendocument.image-template
+!:ext oti
# EPUB (OEBPS) books using OCF (OEBPS Container Format)
# https://www.idpf.org/ocf/ocf1.0/download/ocf10.htm, section 4.
@@ -1206,12 +1265,33 @@
>>>62 string draw.template+zip Draw template, version 14-16
!:mime application/x-vnd.corel.draw.template+zip
!:ext cdrt
->>>62 string zcf.draw.document+zip Draw drawing, version 17-21
+>>>62 string zcf.draw.document+zip Draw drawing, version 17-22
!:mime application/x-vnd.corel.zcf.draw.document+zip
!:ext cdr
->>>62 string zcf.draw.template+zip Draw template, version 17-21
+>>>62 string zcf.draw.template+zip Draw template, version 17-22
!:mime application/x-vnd.corel.zcf.draw.template+zip
!:ext cdt/cdrt
+# URL: http://product.corel.com/help/CorelDRAW/540240626/Main/EN/Doc/CorelDRAW-Other-file-formats.html
+>>>62 string zcf.pattern+zip Draw pattern, version 22
+!:mime application/x-vnd.corel.zcf.pattern+zip
+!:ext pat
+# URL: https://en.wikipedia.org/wiki/Corel_Designer
+# Reference: http://fileformats.archiveteam.org/wiki/Corel_Designer
+# Note: called by TrID "Corel DESIGN graphics"
+>>>62 string designer.document+zip DESIGNER graphics, version 14-16
+!:mime application/x-vnd.corel.designer.document+zip
+!:ext des
+>>>62 string zcf.designer.document+zip DESIGNER graphics, version 17-21
+!:mime application/x-vnd.corel.zcf.designer.document+zip
+!:ext des
+# URL: http://product.corel.com/help/CorelDRAW/540223850/Main/EN/Documentation/
+# CorelDRAW-Corel-Symbol-Library-CSL.html
+>>>62 string symbol.library+zip Symbol Library, version 6-16.3
+!:mime application/x-vnd.corel.symbol.library+zip
+!:ext csl
+>>>62 string zcf.symbol.library+zip Symbol Library, version 17-22
+!:mime application/x-vnd.corel.zcf.symbol.library+zip
+!:ext csl
# Catch other ZIP-with-mimetype formats
# In a ZIP file, the bytes immediately after a member's contents are
@@ -1239,16 +1319,19 @@
>>>>38 search/64 .app/ iOS App
!:mime application/x-ios-app
+>30 search/100/b application/epub+zip EPUB document
+!:mime application/epub+zip
# Generic zip archives (Greg Roelofs, c/o [email protected])
# Next line excludes specialized formats:
>(26.s+30) leshort !0xcafe
->>26 string !\x8\0\0\0mimetype Zip archive data
+>>30 search/100/b !application/epub+zip
+>>>26 string !\x8\0\0\0mimetype Zip archive data
!:mime application/zip
->>>4 beshort x \b, at least
->>>4 use zipversion
->>>4 beshort x to extract
->>>0x161 string WINZIP \b, WinZIP self-extracting
+>>>>4 beshort x \b, at least
+>>>>4 use zipversion
+>>>>4 beshort x to extract
+>>>>0x161 string WINZIP \b, WinZIP self-extracting
# StarView Metafile
# From Pierre Ducroquet <[email protected]>
Index: src/external/bsd/file/dist/magic/magdir/elf
diff -u src/external/bsd/file/dist/magic/magdir/elf:1.18 src/external/bsd/file/dist/magic/magdir/elf:1.19
--- src/external/bsd/file/dist/magic/magdir/elf:1.18 Mon Dec 16 21:31:05 2019
+++ src/external/bsd/file/dist/magic/magdir/elf Sun Jun 14 20:37:24 2020
@@ -1,6 +1,6 @@
#------------------------------------------------------------------------------
-# $File: elf,v 1.79 2019/12/16 04:24:01 christos Exp $
+# $File: elf,v 1.80 2020/02/12 22:17:33 christos Exp $
# elf: file(1) magic for ELF executables
#
# We have to check the byte order flag to see what byte order all the
@@ -50,8 +50,9 @@
!:mime application/x-object
>16 leshort 2 executable,
!:mime application/x-executable
->16 leshort 3 shared object,
-!:mime application/x-sharedlib
+>16 leshort 3 ${x?pie executable:shared object},
+
+!:mime application/x-${x?pie-executable:sharedlib}
>16 leshort 4 core file,
!:mime application/x-coredump
# OS-specific
Index: src/external/bsd/file/dist/magic/magdir/filesystems
diff -u src/external/bsd/file/dist/magic/magdir/filesystems:1.16 src/external/bsd/file/dist/magic/magdir/filesystems:1.17
--- src/external/bsd/file/dist/magic/magdir/filesystems:1.16 Mon Dec 16 21:31:05 2019
+++ src/external/bsd/file/dist/magic/magdir/filesystems Sun Jun 14 20:37:24 2020
@@ -1,5 +1,5 @@
#------------------------------------------------------------------------------
-# $File: filesystems,v 1.131 2019/11/15 23:49:38 christos Exp $
+# $File: filesystems,v 1.133 2020/05/17 19:32:00 christos Exp $
# filesystems: file(1) magic for different filesystems
#
0 name partid
@@ -1994,7 +1994,7 @@
# to display CD-ROM (70=81-11) after MBR (113=40+72+1), partition-table (71=50+21) and before Apple Driver Map (51)
#!:strength -11
# to display CD-ROM (114=81+33) before MBR (113=40+72+1), partition-table (71=50+21) and Apple Driver Map (51)
-!:strength +34
+!:strength +35
>0 use cdrom
# URL: https://en.wikipedia.org/wiki/NRG_(file_format)
@@ -2182,7 +2182,7 @@
>0 use squashfs
0 string hsqs Squashfs filesystem, little endian,
->0 use ^squashfs
+>0 use \^squashfs
# AFS Dump Magic
# From: Ty Sarna <[email protected]>
Index: src/external/bsd/file/dist/magic/magdir/parix
diff -u src/external/bsd/file/dist/magic/magdir/parix:1.2 src/external/bsd/file/dist/magic/magdir/parix:1.3
--- src/external/bsd/file/dist/magic/magdir/parix:1.2 Sun Mar 8 13:54:23 2020
+++ src/external/bsd/file/dist/magic/magdir/parix Sun Jun 14 20:37:24 2020
@@ -1,6 +1,6 @@
#------------------------------------------------------------------------------
-# $File: parix,v 1.4 2009/09/19 16:28:11 christos Exp $
+# $File: parix,v 1.5 2020/03/08 22:18:32 christos Exp $
#
# Parix COFF executables
# From: Ignatios Souvatzis <[email protected]>
Index: src/external/bsd/file/dist/magic/magdir/pgp
diff -u src/external/bsd/file/dist/magic/magdir/pgp:1.7 src/external/bsd/file/dist/magic/magdir/pgp:1.8
--- src/external/bsd/file/dist/magic/magdir/pgp:1.7 Wed May 22 13:26:05 2019
+++ src/external/bsd/file/dist/magic/magdir/pgp Sun Jun 14 20:37:24 2020
@@ -1,6 +1,6 @@
#------------------------------------------------------------------------------
-# $File: pgp,v 1.17 2019/04/19 00:42:27 christos Exp $
+# $File: pgp,v 1.21 2020/03/20 17:11:05 christos Exp $
# pgp: file(1) magic for Pretty Good Privacy
# see https://lists.gnupg.org/pipermail/gnupg-devel/1999-September/016052.html
#
@@ -58,16 +58,36 @@
#>15 string SIGNED\040MESSAGE- signed message
#>15 string PGP\040SIGNATURE- signature
+# Update: Joerg Jenderek
+# URL: http://en.wikipedia.org/wiki/Pretty_Good_Privacy
+# Reference: https://reposcope.com/mimetype/application/pgp-keys
+2 string ---BEGIN\040PGP\040PRIVATE\040KEY\040BLOCK- PGP private key block
+#!:mime text/PGP
+!:mime application/pgp-keys
+!:ext asc
2 string ---BEGIN\040PGP\040PUBLIC\040KEY\040BLOCK- PGP public key block
!:mime application/pgp-keys
+!:ext asc
>10 search/100 \n\n
>>&0 use pgp
0 string -----BEGIN\040PGP\040MESSAGE- PGP message
-!:mime application/pgp
+# https://reposcope.com/mimetype/application/pgp-encrypted
+#!:mime application/pgp
+!:mime application/pgp-encrypted
+!:ext asc
+#!:ext asc/pgp/gpg
>10 search/100 \n\n
>>&0 use pgp
+# Reference: https://www.gnupg.org/gph/en/manual/x135.html
+0 string -----BEGIN\040PGP\040SIGNED\040MESSAGE- PGP signed message
+#!:mime text/plain
+!:mime text/PGP
+#!:mime application/pgp
+!:ext asc
0 string -----BEGIN\040PGP\040SIGNATURE- PGP signature
+# https://reposcope.com/mimetype/application/pgp-signature
!:mime application/pgp-signature
+!:ext asc
>10 search/100 \n\n
>>&0 use pgp
@@ -127,8 +147,8 @@
# 1024b RSA encrypted data
0 string \x84\x8c\x03 PGP RSA encrypted session key -
->3 lelong x keyid: %X
->7 lelong x %X
+>3 belong x keyid: %08X
+>7 belong x %08X
>11 byte 0x01 RSA (Encrypt or Sign) 1024b
>11 byte 0x02 RSA Encrypt-Only 1024b
>12 string \x04\x00
@@ -144,8 +164,8 @@
# 2048b RSA encrypted data
0 string \x85\x01\x0c\x03 PGP RSA encrypted session key -
->4 lelong x keyid: %X
->8 lelong x %X
+>4 belong x keyid: %08X
+>8 belong x %08X
>12 byte 0x01 RSA (Encrypt or Sign) 2048b
>12 byte 0x02 RSA Encrypt-Only 2048b
>13 string \x08\x00
@@ -161,8 +181,8 @@
# 3072b RSA encrypted data
0 string \x85\x01\x8c\x03 PGP RSA encrypted session key -
->4 lelong x keyid: %X
->8 lelong x %X
+>4 belong x keyid: %08X
+>8 belong x %08X
>12 byte 0x01 RSA (Encrypt or Sign) 3072b
>12 byte 0x02 RSA Encrypt-Only 3072b
>13 string \x0c\x00
@@ -175,11 +195,11 @@
>13 string \x0b\xf9
>399 byte 0xd2 .
-# 3072b RSA encrypted data
+# 4096b RSA encrypted data
0 string \x85\x02\x0c\x03 PGP RSA encrypted session key -
->4 lelong x keyid: %X
->8 lelong x %X
+>4 belong x keyid: %08X
+>8 belong x %08X
>12 byte 0x01 RSA (Encrypt or Sign) 4096b
>12 byte 0x02 RSA Encrypt-Only 4096b
>13 string \x10\x00
@@ -192,13 +212,13 @@
>13 string \x0f\xf9
>527 byte 0xd2 .
-# 4096b RSA encrypted data
+# 8192b RSA encrypted data
0 string \x85\x04\x0c\x03 PGP RSA encrypted session key -
->4 lelong x keyid: %X
->8 lelong x %X
->12 byte 0x01 RSA (Encrypt or Sign) 8129b
->12 byte 0x02 RSA Encrypt-Only 8129b
+>4 belong x keyid: %08X
+>8 belong x %08X
+>12 byte 0x01 RSA (Encrypt or Sign) 8192b
+>12 byte 0x02 RSA Encrypt-Only 8192b
>13 string \x20\x00
>13 string \x1f\xff
>13 string \x1f\xfe
@@ -209,6 +229,51 @@
>13 string \x1f\xf9
>1039 byte 0xd2 .
+# 1024b Elgamal encrypted data
+
+0 string \x85\x01\x0e\x03 PGP Elgamal encrypted session key -
+>4 belong x keyid: %08X
+>8 belong x %08X
+>12 byte 0x10 Elgamal Encrypt-Only 1024b.
+>13 string \x04\x00
+>13 string \x03\xff
+>13 string \x03\xfe
+>13 string \x03\xfd
+>13 string \x03\xfc
+>13 string \x03\xfb
+>13 string \x03\xfa
+>13 string \x03\xf9
+
+# 2048b Elgamal encrypted data
+
+0 string \x85\x02\x0e\x03 PGP Elgamal encrypted session key -
+>4 belong x keyid: %08X
+>8 belong x %08X
+>12 byte 0x10 Elgamal Encrypt-Only 2048b.
+>13 string \x08\x00
+>13 string \x07\xff
+>13 string \x07\xfe
+>13 string \x07\xfd
+>13 string \x07\xfc
+>13 string \x07\xfb
+>13 string \x07\xfa
+>13 string \x07\xf9
+
+# 3072b Elgamal encrypted data
+
+0 string \x85\x03\x0e\x03 PGP Elgamal encrypted session key -
+>4 belong x keyid: %08X
+>8 belong x %08X
+>12 byte 0x10 Elgamal Encrypt-Only 3072b.
+>13 string \x0c\x00
+>13 string \x0b\xff
+>13 string \x0b\xfe
+>13 string \x0b\xfd
+>13 string \x0b\xfc
+>13 string \x0b\xfb
+>13 string \x0b\xfa
+>13 string \x0b\xf9
+
# crypto algo mapper
0 name crypto
Index: src/external/bsd/file/dist/src/apprentice.c
diff -u src/external/bsd/file/dist/src/apprentice.c:1.24 src/external/bsd/file/dist/src/apprentice.c:1.25
--- src/external/bsd/file/dist/src/apprentice.c:1.24 Mon Dec 16 21:31:05 2019
+++ src/external/bsd/file/dist/src/apprentice.c Sun Jun 14 20:37:24 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: apprentice.c,v 1.24 2019/12/17 02:31:05 christos Exp $ */
+/* $NetBSD: apprentice.c,v 1.25 2020/06/15 00:37:24 christos Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@@ -35,9 +35,9 @@
#ifndef lint
#if 0
-FILE_RCSID("@(#)$File: apprentice.c,v 1.284 2019/06/29 22:31:04 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.297 2020/05/09 18:57:15 christos Exp $")
#else
-__RCSID("$NetBSD: apprentice.c,v 1.24 2019/12/17 02:31:05 christos Exp $");
+__RCSID("$NetBSD: apprentice.c,v 1.25 2020/06/15 00:37:24 christos Exp $");
#endif
#endif /* lint */
@@ -126,6 +126,7 @@ private void apprentice_list(struct mlis
private struct magic_map *apprentice_load(struct magic_set *,
const char *, int);
private struct mlist *mlist_alloc(void);
+private void mlist_free_all(struct magic_set *);
private void mlist_free(struct mlist *);
private void byteswap(struct magic *, uint32_t);
private void bs1(struct magic *);
@@ -143,10 +144,14 @@ private int apprentice_compile(struct ma
private int check_format_type(const char *, int, const char **);
private int check_format(struct magic_set *, struct magic *);
private int get_op(char);
-private int parse_mime(struct magic_set *, struct magic_entry *, const char *);
-private int parse_strength(struct magic_set *, struct magic_entry *, const char *);
-private int parse_apple(struct magic_set *, struct magic_entry *, const char *);
-private int parse_ext(struct magic_set *, struct magic_entry *, const char *);
+private int parse_mime(struct magic_set *, struct magic_entry *, const char *,
+ size_t);
+private int parse_strength(struct magic_set *, struct magic_entry *,
+ const char *, size_t);
+private int parse_apple(struct magic_set *, struct magic_entry *, const char *,
+ size_t);
+private int parse_ext(struct magic_set *, struct magic_entry *, const char *,
+ size_t);
private size_t magicsize = sizeof(struct magic);
@@ -156,7 +161,8 @@ private const char usg_hdr[] = "cont\tof
private struct {
const char *name;
size_t len;
- int (*fun)(struct magic_set *, struct magic_entry *, const char *);
+ int (*fun)(struct magic_set *, struct magic_entry *, const char *,
+ size_t);
} bang[] = {
#define DECLARE_FIELD(name) { # name, sizeof(# name) - 1, parse_ ## name }
DECLARE_FIELD(mime),
@@ -266,6 +272,8 @@ static const struct type_tbl_s type_tbl[
{ XX("use"), FILE_USE, FILE_FMT_NONE },
{ XX("clear"), FILE_CLEAR, FILE_FMT_NONE },
{ XX("der"), FILE_DER, FILE_FMT_STR },
+ { XX("guid"), FILE_GUID, FILE_FMT_STR },
+ { XX("offset"), FILE_OFFSET, FILE_FMT_QUAD },
{ XX_NULL, FILE_INVALID, FILE_FMT_NONE },
};
@@ -457,8 +465,6 @@ apprentice_1(struct magic_set *ms, const
#ifndef COMPILE_ONLY
map = apprentice_map(ms, fn);
- if (map == RCAST(struct magic_map *, -1))
- return -1;
if (map == NULL) {
if (ms->flags & MAGIC_CHECK)
file_magwarn(ms, "using regular magic file `%s'", fn);
@@ -469,6 +475,11 @@ apprentice_1(struct magic_set *ms, const
for (i = 0; i < MAGIC_SETS; i++) {
if (add_mlist(ms->mlist[i], map, i) == -1) {
+ /* failed to add to any list, free explicitly */
+ if (i == 0)
+ apprentice_unmap(map);
+ else
+ mlist_free_all(ms);
file_oomem(ms, sizeof(*ml));
return -1;
}
@@ -519,6 +530,7 @@ file_ms_alloc(int flags)
}
ms->o.buf = ms->o.pbuf = NULL;
+ ms->o.blen = 0;
len = (ms->c.len = 10) * sizeof(*ms->c.li);
if ((ms->c.li = CAST(struct level_info *, malloc(len))) == NULL)
@@ -588,6 +600,17 @@ mlist_alloc(void)
}
private void
+mlist_free_all(struct magic_set *ms)
+{
+ size_t i;
+
+ for (i = 0; i < MAGIC_SETS; i++) {
+ mlist_free(ms->mlist[i]);
+ ms->mlist[i] = NULL;
+ }
+}
+
+private void
mlist_free_one(struct mlist *ml)
{
if (ml->map)
@@ -603,9 +626,10 @@ mlist_free(struct mlist *mlist)
if (mlist == NULL)
return;
- for (ml = mlist->next; ml != mlist; ml = next) {
+ for (ml = mlist->next; ml != mlist;) {
next = ml->next;
mlist_free_one(ml);
+ ml = next;
}
mlist_free_one(mlist);
}
@@ -650,10 +674,7 @@ buffer_apprentice(struct magic_set *ms,
return 0;
fail:
- for (i = 0; i < MAGIC_SETS; i++) {
- mlist_free(ms->mlist[i]);
- ms->mlist[i] = NULL;
- }
+ mlist_free_all(ms);
return -1;
}
#endif
@@ -664,7 +685,7 @@ file_apprentice(struct magic_set *ms, co
{
char *p, *mfn;
int fileerr, errs = -1;
- size_t i;
+ size_t i, j;
(void)file_reset(ms, 0);
@@ -682,9 +703,9 @@ file_apprentice(struct magic_set *ms, co
mlist_free(ms->mlist[i]);
if ((ms->mlist[i] = mlist_alloc()) == NULL) {
file_oomem(ms, sizeof(*ms->mlist[i]));
- while (i-- > 0) {
- mlist_free(ms->mlist[i]);
- ms->mlist[i] = NULL;
+ for (j = 0; j < i; j++) {
+ mlist_free(ms->mlist[j]);
+ ms->mlist[j] = NULL;
}
free(mfn);
return -1;
@@ -835,9 +856,14 @@ typesize(int type)
case FILE_DOUBLE:
case FILE_BEDOUBLE:
case FILE_LEDOUBLE:
+ case FILE_OFFSET:
return 8;
+
+ case FILE_GUID:
+ return 16;
+
default:
- return CAST(size_t, ~0);
+ return FILE_BADSIZE;
}
}
@@ -891,8 +917,10 @@ apprentice_magic_strength(const struct m
case FILE_DOUBLE:
case FILE_BEDOUBLE:
case FILE_LEDOUBLE:
+ case FILE_GUID:
+ case FILE_OFFSET:
ts = typesize(m->type);
- if (ts == CAST(size_t, ~0))
+ if (ts == FILE_BADSIZE)
abort();
val += ts * MULT;
break;
@@ -1083,6 +1111,8 @@ set_test_type(struct magic *mstart, stru
case FILE_BEDOUBLE:
case FILE_LEDOUBLE:
case FILE_DER:
+ case FILE_GUID:
+ case FILE_OFFSET:
mstart->flag |= BINTEST;
break;
case FILE_STRING:
@@ -1207,7 +1237,8 @@ load_1(struct magic_set *ms, int action,
continue;
}
if ((*bang[i].fun)(ms, &me,
- line + bang[i].len + 2) != 0) {
+ line + bang[i].len + 2,
+ len - bang[i].len - 2) != 0) {
(*errs)++;
continue;
}
@@ -1387,9 +1418,10 @@ apprentice_load(struct magic_set *ms, co
}
if (files >= maxfiles) {
size_t mlen;
+ char **nfilearr;
maxfiles = (maxfiles + 1) * 2;
mlen = maxfiles * sizeof(*filearr);
- if ((filearr = CAST(char **,
+ if ((nfilearr = CAST(char **,
realloc(filearr, mlen))) == NULL) {
file_oomem(ms, mlen);
free(mfn);
@@ -1397,6 +1429,7 @@ apprentice_load(struct magic_set *ms, co
errs++;
goto out;
}
+ filearr = nfilearr;
}
filearr[files++] = mfn;
}
@@ -1408,6 +1441,7 @@ apprentice_load(struct magic_set *ms, co
free(filearr[i]);
}
free(filearr);
+ filearr = NULL;
}
} else
load_1(ms, action, fn, &errs, mset);
@@ -1442,6 +1476,7 @@ apprentice_load(struct magic_set *ms, co
}
out:
+ free(filearr);
for (j = 0; j < MAGIC_SETS; j++)
magic_entry_free(mset[j].me, mset[j].count);
@@ -1505,6 +1540,7 @@ file_signextend(struct magic_set *ms, st
case FILE_DOUBLE:
case FILE_BEDOUBLE:
case FILE_LEDOUBLE:
+ case FILE_OFFSET:
v = CAST(int64_t, v);
break;
case FILE_STRING:
@@ -1519,12 +1555,13 @@ file_signextend(struct magic_set *ms, st
case FILE_USE:
case FILE_CLEAR:
case FILE_DER:
+ case FILE_GUID:
break;
default:
if (ms->flags & MAGIC_CHECK)
file_magwarn(ms, "cannot happen: m->type=%d\n",
m->type);
- return ~0U;
+ return FILE_BADSIZE;
}
}
return v;
@@ -1926,6 +1963,10 @@ parse(struct magic_set *ms, struct magic
}
/* get offset, then skip over it */
+ if (*l == '-') {
+ ++l; /* step over */
+ m->flag |= OFFNEGATIVE;
+ }
m->offset = CAST(int32_t, strtol(l, &t, 0));
if (l == t) {
if (ms->flags & MAGIC_CHECK)
@@ -2230,7 +2271,8 @@ parse(struct magic_set *ms, struct magic
* if valid
*/
private int
-parse_strength(struct magic_set *ms, struct magic_entry *me, const char *line)
+parse_strength(struct magic_set *ms, struct magic_entry *me, const char *line,
+ size_t len __attribute__((__unused__)))
{
const char *l = line;
char *el;
@@ -2292,7 +2334,8 @@ goodchar(unsigned char x, const char *ex
private int
parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line,
- off_t off, size_t len, const char *name, const char *extra, int nt)
+ size_t llen, off_t off, size_t len, const char *name, const char *extra,
+ int nt)
{
size_t i;
const char *l = line;
@@ -2313,7 +2356,8 @@ parse_extra(struct magic_set *ms, struct
}
EATAB;
- for (i = 0; *l && i < len && goodchar(*l, extra); buf[i++] = *l++)
+ for (i = 0; *l && i < llen && i < len && goodchar(*l, extra);
+ buf[i++] = *l++)
continue;
if (i == len && *l) {
@@ -2342,11 +2386,12 @@ parse_extra(struct magic_set *ms, struct
* magic[index - 1]
*/
private int
-parse_apple(struct magic_set *ms, struct magic_entry *me, const char *line)
+parse_apple(struct magic_set *ms, struct magic_entry *me, const char *line,
+ size_t len)
{
struct magic *m = &me->mp[0];
- return parse_extra(ms, me, line,
+ return parse_extra(ms, me, line, len,
CAST(off_t, offsetof(struct magic, apple)),
sizeof(m->apple), "APPLE", "!+-./?", 0);
}
@@ -2355,11 +2400,12 @@ parse_apple(struct magic_set *ms, struct
* Parse a comma-separated list of extensions
*/
private int
-parse_ext(struct magic_set *ms, struct magic_entry *me, const char *line)
+parse_ext(struct magic_set *ms, struct magic_entry *me, const char *line,
+ size_t len)
{
struct magic *m = &me->mp[0];
- return parse_extra(ms, me, line,
+ return parse_extra(ms, me, line, len,
CAST(off_t, offsetof(struct magic, ext)),
sizeof(m->ext), "EXTENSION", ",!+-/@?_$", 0);
}
@@ -2369,11 +2415,12 @@ parse_ext(struct magic_set *ms, struct m
* if valid
*/
private int
-parse_mime(struct magic_set *ms, struct magic_entry *me, const char *line)
+parse_mime(struct magic_set *ms, struct magic_entry *me, const char *line,
+ size_t len)
{
struct magic *m = &me->mp[0];
- return parse_extra(ms, me, line,
+ return parse_extra(ms, me, line, len,
CAST(off_t, offsetof(struct magic, mimetype)),
sizeof(m->mimetype), "MIME", "+-/.$?:{}", 1);
}
@@ -2690,6 +2737,11 @@ getvalue(struct magic_set *ms, struct ma
if (errno == 0)
*p = ep;
return 0;
+ case FILE_GUID:
+ if (file_parse_guid(*p, m->value.guid) == -1)
+ return -1;
+ *p += FILE_GUID_SIZE - 1;
+ return 0;
default:
errno = 0;
ull = CAST(uint64_t, strtoull(*p, &ep, 0));
@@ -2701,7 +2753,7 @@ getvalue(struct magic_set *ms, struct ma
uint64_t x;
const char *q;
- if (ts == CAST(size_t, ~0)) {
+ if (ts == FILE_BADSIZE) {
file_magwarn(ms,
"Expected numeric type got `%s'",
type_tbl[m->type].name);
@@ -2898,8 +2950,12 @@ getstr(struct magic_set *ms, struct magi
out:
*p = '\0';
m->vallen = CAST(unsigned char, (p - origp));
- if (m->type == FILE_PSTRING)
- m->vallen += CAST(unsigned char, file_pstring_length_size(m));
+ if (m->type == FILE_PSTRING) {
+ size_t l = file_pstring_length_size(ms, m);
+ if (l == FILE_BADSIZE)
+ return NULL;
+ m->vallen += CAST(unsigned char, l);
+ }
return s;
}
@@ -2929,7 +2985,7 @@ file_showstr(FILE *fp, const char *s, si
char c;
for (;;) {
- if (len == ~0U) {
+ if (len == FILE_BADSIZE) {
c = *s++;
if (c == '\0')
break;
@@ -3083,13 +3139,11 @@ apprentice_map(struct magic_set *ms, con
file_badread(ms);
goto error;
}
-#define RET 1
#endif
(void)close(fd);
fd = -1;
if (check_buffer(ms, map, dbname) != 0) {
- rv = RCAST(struct magic_map *, -1);
goto error;
}
#ifdef QUICK
@@ -3363,7 +3417,7 @@ bs1(struct magic *m)
}
protected size_t
-file_pstring_length_size(const struct magic *m)
+file_pstring_length_size(struct magic_set *ms, const struct magic *m)
{
switch (m->str_flags & PSTRING_LEN) {
case PSTRING_1_LE:
@@ -3375,12 +3429,15 @@ file_pstring_length_size(const struct ma
case PSTRING_4_BE:
return 4;
default:
- abort(); /* Impossible */
- return 1;
+ file_error(ms, 0, "corrupt magic file "
+ "(bad pascal string length %d)",
+ m->str_flags & PSTRING_LEN);
+ return FILE_BADSIZE;
}
}
protected size_t
-file_pstring_get_length(const struct magic *m, const char *ss)
+file_pstring_get_length(struct magic_set *ms, const struct magic *m,
+ const char *ss)
{
size_t len = 0;
const unsigned char *s = RCAST(const unsigned char *, ss);
@@ -3415,11 +3472,18 @@ file_pstring_get_length(const struct mag
len = (s0 << 24) | (s1 << 16) | (s2 << 8) | s3;
break;
default:
- abort(); /* Impossible */
+ file_error(ms, 0, "corrupt magic file "
+ "(bad pascal string length %d)",
+ m->str_flags & PSTRING_LEN);
+ return FILE_BADSIZE;
}
- if (m->str_flags & PSTRING_LENGTH_INCLUDES_ITSELF)
- len -= file_pstring_length_size(m);
+ if (m->str_flags & PSTRING_LENGTH_INCLUDES_ITSELF) {
+ size_t l = file_pstring_length_size(ms, m);
+ if (l == FILE_BADSIZE)
+ return l;
+ len -= l;
+ }
return len;
}
Index: src/external/bsd/file/dist/src/file.h
diff -u src/external/bsd/file/dist/src/file.h:1.24 src/external/bsd/file/dist/src/file.h:1.25
--- src/external/bsd/file/dist/src/file.h:1.24 Mon Dec 16 21:31:05 2019
+++ src/external/bsd/file/dist/src/file.h Sun Jun 14 20:37:24 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: file.h,v 1.24 2019/12/17 02:31:05 christos Exp $ */
+/* $NetBSD: file.h,v 1.25 2020/06/15 00:37:24 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.208 2019/06/26 20:31:31 christos Exp $
+ * @(#)$File: file.h,v 1.220 2020/06/08 17:38:27 christos Exp $
*/
#ifndef __file_h__
@@ -38,7 +38,15 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+
#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+
#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS
#endif
@@ -46,28 +54,33 @@
#define __STDC_FORMAT_MACROS
#endif
-#ifdef WIN32
- #ifdef _WIN64
- #define SIZE_T_FORMAT "I64"
- #else
- #define SIZE_T_FORMAT ""
- #endif
- #define INT64_T_FORMAT "I64"
- #define INTMAX_T_FORMAT "I64"
+#ifdef _WIN32
+# ifdef PRIu32
+# ifdef _WIN64
+# define SIZE_T_FORMAT PRIu64
+# else
+# define SIZE_T_FORMAT PRIu32
+# endif
+# define INT64_T_FORMAT PRIi64
+# define INTMAX_T_FORMAT PRIiMAX
+# else
+# ifdef _WIN64
+# define SIZE_T_FORMAT "I64"
+# else
+# define SIZE_T_FORMAT ""
+# endif
+# define INT64_T_FORMAT "I64"
+# define INTMAX_T_FORMAT "I64"
+# endif
#else
- #define SIZE_T_FORMAT "z"
- #define INT64_T_FORMAT "ll"
- #define INTMAX_T_FORMAT "j"
-#endif
-#include <stdint.h>
+# define SIZE_T_FORMAT "z"
+# define INT64_T_FORMAT "ll"
+# define INTMAX_T_FORMAT "j"
#endif
#include <stdio.h> /* Include that here, to make sure __P gets defined */
#include <errno.h>
#include <fcntl.h> /* For open and flags */
-#ifdef HAVE_INTTYPES_H
-#include <inttypes.h>
-#endif
#include <regex.h>
#include <time.h>
#include <sys/types.h>
@@ -132,18 +145,16 @@
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif
-#ifndef FILE_BYTES_MAX
-# define FILE_BYTES_MAX (1024 * 1024) /* how much of the file to look at */
-#endif
-#define MAXMAGIS 8192 /* max entries in any one magic file
- or directory */
+#define FILE_BADSIZE CAST(size_t, ~0ul)
#define MAXDESC 64 /* max len of text description/MIME type */
#define MAXMIME 80 /* max len of text MIME type */
-#define MAXstring 96 /* max len of "string" types */
+#define MAXstring 128 /* max len of "string" types */
#define MAGICNO 0xF11E041C
-#define VERSIONNO 14
-#define FILE_MAGICSIZE 344
+#define VERSIONNO 16
+#define FILE_MAGICSIZE 376
+
+#define FILE_GUID_SIZE sizeof("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
#define FILE_LOAD 0
#define FILE_CHECK 1
@@ -170,6 +181,7 @@ union VALUETYPE {
uint8_t hq[8]; /* 8 bytes of a fixed-endian "quad" */
char s[MAXstring]; /* the search string or regex pattern */
unsigned char us[MAXstring];
+ uint64_t guid[2];
float f;
double d;
};
@@ -186,6 +198,7 @@ struct magic {
#define BINTEST 0x20 /* test is for a binary type (set only
for top-level tests) */
#define TEXTTEST 0x40 /* for passing to file_softmagic */
+#define OFFNEGATIVE 0x80 /* relative to the end of file */
uint8_t factor;
@@ -243,7 +256,9 @@ struct magic {
#define FILE_USE 46
#define FILE_CLEAR 47
#define FILE_DER 48
-#define FILE_NAMES_SIZE 49 /* size of array to contain all names */
+#define FILE_GUID 49
+#define FILE_OFFSET 50
+#define FILE_NAMES_SIZE 51 /* size of array to contain all names */
#define IS_STRING(t) \
((t) == FILE_STRING || \
@@ -407,9 +422,10 @@ struct magic_set {
} c;
struct out {
char *buf; /* Accumulation buffer */
+ size_t blen; /* Length of buffer */
char *pbuf; /* Printable buffer */
} o;
- uint32_t offset; /* a copy of m->offset while we */
+ uint32_t offset; /* a copy of m->offset while we */
/* are working on the magic entry */
uint32_t eoffset; /* offset from end of file */
int error;
@@ -438,11 +454,14 @@ struct magic_set {
uint16_t elf_notes_max;
uint16_t regex_max;
size_t bytes_max; /* number of bytes to read from file */
-#define FILE_INDIR_MAX 50
-#define FILE_NAME_MAX 30
-#define FILE_ELF_SHNUM_MAX 32768
-#define FILE_ELF_PHNUM_MAX 2048
+#ifndef FILE_BYTES_MAX
+# define FILE_BYTES_MAX (1024 * 1024) /* how much of the file to look at */
+#endif
#define FILE_ELF_NOTES_MAX 256
+#define FILE_ELF_PHNUM_MAX 2048
+#define FILE_ELF_SHNUM_MAX 32768
+#define FILE_INDIR_MAX 50
+#define FILE_NAME_MAX 50
#define FILE_REGEX_MAX 8192
};
@@ -452,7 +471,7 @@ typedef unsigned long unichar;
struct stat;
#define FILE_T_LOCAL 1
#define FILE_T_WINDOWS 2
-protected const char *file_fmttime(uint64_t, int, char *);
+protected const char *file_fmttime(char *, size_t, uint64_t, int);
protected struct magic_set *file_ms_alloc(int);
protected void file_ms_free(struct magic_set *);
protected int file_default(struct magic_set *, size_t);
@@ -463,7 +482,11 @@ protected int file_pipe2file(struct magi
protected int file_vprintf(struct magic_set *, const char *, va_list)
__attribute__((__format__(__printf__, 2, 0)));
protected int file_separator(struct magic_set *);
+protected char *file_copystr(char *, size_t, size_t, const char *);
+protected int file_checkfmt(char *, size_t, const char *);
protected size_t file_printedlen(const struct magic_set *);
+protected int file_print_guid(char *, size_t, const uint64_t *);
+protected int file_parse_guid(const char *, uint64_t *);
protected int file_replace(struct magic_set *, const char *, const char *);
protected int file_printf(struct magic_set *, const char *, ...)
__attribute__((__format__(__printf__, 2, 3)));
@@ -508,8 +531,10 @@ protected ssize_t sread(int, void *, siz
protected int file_check_mem(struct magic_set *, unsigned int);
protected int file_looks_utf8(const unsigned char *, size_t, unichar *,
size_t *);
-protected size_t file_pstring_length_size(const struct magic *);
-protected size_t file_pstring_get_length(const struct magic *, const char *);
+protected size_t file_pstring_length_size(struct magic_set *,
+ const struct magic *);
+protected size_t file_pstring_get_length(struct magic_set *,
+ const struct magic *, const char *);
protected char * file_printable(char *, size_t, const char *, size_t);
#ifdef __EMX__
protected int file_os2_apptype(struct magic_set *, const char *, const void *,
@@ -547,6 +572,7 @@ protected void file_regerror(file_regex_
typedef struct {
char *buf;
+ size_t blen;
uint32_t offset;
} file_pushbuf_t;
Index: src/external/bsd/file/dist/src/compress.c
diff -u src/external/bsd/file/dist/src/compress.c:1.19 src/external/bsd/file/dist/src/compress.c:1.20
--- src/external/bsd/file/dist/src/compress.c:1.19 Mon Dec 16 21:31:05 2019
+++ src/external/bsd/file/dist/src/compress.c Sun Jun 14 20:37:24 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: compress.c,v 1.19 2019/12/17 02:31:05 christos Exp $ */
+/* $NetBSD: compress.c,v 1.20 2020/06/15 00:37:24 christos Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@@ -38,9 +38,9 @@
#ifndef lint
#if 0
-FILE_RCSID("@(#)$File: compress.c,v 1.124 2019/07/21 11:42:09 christos Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.127 2020/05/31 00:11:06 christos Exp $")
#else
-__RCSID("$NetBSD: compress.c,v 1.19 2019/12/17 02:31:05 christos Exp $");
+__RCSID("$NetBSD: compress.c,v 1.20 2020/06/15 00:37:24 christos Exp $");
#endif
#endif
@@ -57,7 +57,7 @@ __RCSID("$NetBSD: compress.c,v 1.19 2019
#ifndef HAVE_SIG_T
typedef void (*sig_t)(int);
#endif /* HAVE_SIG_T */
-#if !defined(__MINGW32__) && !defined(WIN32)
+#if !defined(__MINGW32__) && !defined(WIN32) && !defined(__MINGW64__)
#include <sys/ioctl.h>
#endif
#ifdef HAVE_SYS_WAIT_H
@@ -72,12 +72,12 @@ typedef void (*sig_t)(int);
#include <zlib.h>
#endif
-#if defined(HAVE_BZLIB_H) || defined(BZLIBSUPPORT)
+#if defined(HAVE_BZLIB_H) && defined(BZLIBSUPPORT)
#define BUILTIN_BZLIB
#include <bzlib.h>
#endif
-#if defined(HAVE_XZLIB_H) || defined(XZLIBSUPPORT)
+#if defined(HAVE_XZLIB_H) && defined(XZLIBSUPPORT)
#define BUILTIN_XZLIB
#include <lzma.h>
#endif
@@ -167,7 +167,10 @@ static const char *zstd_args[] = {
#define do_bzlib NULL
private const struct {
- const void *magic;
+ union {
+ const char *magic;
+ int (*func)(const unsigned char *);
+ } u;
int maglen;
const char **argv;
void *unused;
@@ -177,26 +180,26 @@ private const struct {
#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 }, /* 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 }, /* 5, packed */
- { "PK\3\4", 4, gzip_args, NULL }, /* 6, pkzipped, */
- /* ...only first file examined */
- { "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 */
+ { { .magic = "\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! */
+ { { .magic = "\037\235" }, 2, uncompress_args, NULL },/* 1, compressed */
+ { { .magic = "\037\213" }, 2, gzip_args, do_zlib },/* 2, gzipped */
+ { { .magic = "\037\236" }, 2, gzip_args, NULL }, /* 3, frozen */
+ { { .magic = "\037\240" }, 2, gzip_args, NULL }, /* 4, SCO LZH */
+ /* the standard pack utilities do not accept standard input */
+ { { .magic = "\037\036" }, 2, gzip_args, NULL }, /* 5, packed */
+ { { .magic = "PK\3\4" }, 4, gzip_args, NULL }, /* 6, pkziped */
+ /* ...only first file examined */
+ { { .magic = "BZh" }, 3, bzip2_args, do_bzlib },/* 7, bzip2-ed */
+ { { .magic = "LZIP" }, 4, lzip_args, NULL }, /* 8, lzip-ed */
+ { { .magic = "\3757zXZ\0" },6, xz_args, NULL }, /* 9, XZ Util */
+ { { .magic = "LRZI" }, 4, lrzip_args, NULL }, /* 10, LRZIP */
+ { { .magic = "\004\"M\030" },4, lz4_args, NULL }, /* 11, LZ4 */
+ { { .magic = "\x28\xB5\x2F\xFD" }, 4, zstd_args, NULL },/* 12, zstd */
+ { { .func = lzmacmp }, -13, xz_args, NULL }, /* 13, lzma */
#ifdef ZLIBSUPPORT
- { RCAST(const void *, zlibcmp), -2, zlib_args, NULL }, /* 14, zlib */
+ { { .func = zlibcmp }, -2, zlib_args, NULL }, /* 14, zlib */
#endif
};
@@ -268,10 +271,9 @@ file_zmagic(struct magic_set *ms, const
if (nbytes < CAST(size_t, abs(compr[i].maglen)))
continue;
if (compr[i].maglen < 0) {
- zm = (RCAST(int (*)(const unsigned char *),
- CCAST(void *, compr[i].magic)))(buf);
+ zm = (*compr[i].u.func)(buf);
} else {
- zm = memcmp(buf, compr[i].magic,
+ zm = memcmp(buf, compr[i].u.magic,
CAST(size_t, compr[i].maglen)) == 0;
}
Index: src/external/bsd/file/dist/src/der.c
diff -u src/external/bsd/file/dist/src/der.c:1.5 src/external/bsd/file/dist/src/der.c:1.6
--- src/external/bsd/file/dist/src/der.c:1.5 Wed May 22 13:26:05 2019
+++ src/external/bsd/file/dist/src/der.c Sun Jun 14 20:37:24 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: der.c,v 1.5 2019/05/22 17:26:05 christos Exp $ */
+/* $NetBSD: der.c,v 1.6 2020/06/15 00:37:24 christos Exp $ */
/*-
* Copyright (c) 2016 Christos Zoulas
@@ -38,11 +38,14 @@
#ifndef lint
#if 0
-FILE_RCSID("@(#)$File: der.c,v 1.16 2019/02/20 02:35:27 christos Exp $")
+FILE_RCSID("@(#)$File: der.c,v 1.20 2020/06/07 19:10:37 christos Exp $")
#else
-__RCSID("$NetBSD: der.c,v 1.5 2019/05/22 17:26:05 christos Exp $");
+__RCSID("$NetBSD: der.c,v 1.6 2020/06/15 00:37:24 christos Exp $");
#endif
#endif
+#else
+#define SIZE_T_FORMAT "z"
+#define CAST(a, b) ((a)(b))
#endif
#include <sys/types.h>
@@ -68,13 +71,13 @@ __RCSID("$NetBSD: der.c,v 1.5 2019/05/22
#define DER_CLASS_APPLICATION 1
#define DER_CLASS_CONTEXT 2
#define DER_CLASS_PRIVATE 3
-#ifdef DEBUG_DER
+#if defined(DEBUG_DER) || defined(TEST_DER)
static const char der_class[] = "UACP";
#endif
#define DER_TYPE_PRIMITIVE 0
#define DER_TYPE_CONSTRUCTED 1
-#ifdef DEBUG_DER
+#if defined(DEBUG_DER) || defined(TEST_DER)
static const char der_type[] = "PC";
#endif
@@ -92,7 +95,7 @@ static const char der_type[] = "PC";
#define DER_TAG_EMBEDDED_PDV 0x0b
#define DER_TAG_UTF8_STRING 0x0c
#define DER_TAG_RELATIVE_OID 0x0d
-#define DER_TAG_RESERVED_1 0x0e
+#define DER_TAG_TIME 0x0e
#define DER_TAG_RESERVED_2 0x0f
#define DER_TAG_SEQUENCE 0x10
#define DER_TAG_SET 0x11
@@ -109,16 +112,23 @@ static const char der_type[] = "PC";
#define DER_TAG_UNIVERSAL_STRING 0x1c
#define DER_TAG_CHARACTER_STRING 0x1d
#define DER_TAG_BMP_STRING 0x1e
-#define DER_TAG_LONG 0x1f
+#define DER_TAG_DATE 0x1f
+#define DER_TAG_TIME_OF_DAY 0x20
+#define DER_TAG_DATE_TIME 0x21
+#define DER_TAG_DURATION 0x22
+#define DER_TAG_OID_IRI 0x23
+#define DER_TAG_RELATIVE_OID_IRI 0x24
+#define DER_TAG_LAST 0x25
static const char *der__tag[] = {
"eoc", "bool", "int", "bit_str", "octet_str",
"null", "obj_id", "obj_desc", "ext", "real",
- "enum", "embed", "utf8_str", "oid", "res1",
+ "enum", "embed", "utf8_str", "rel_oid", "time",
"res2", "seq", "set", "num_str", "prt_str",
- "t61_str", "vid_str", "ia5_str", "utc_time",
- "gen_time", "gr_str", "vis_str", "gen_str",
- "char_str", "bmp_str", "long"
+ "t61_str", "vid_str", "ia5_str", "utc_time", "gen_time",
+ "gr_str", "vis_str", "gen_str", "univ_str", "char_str",
+ "bmp_str", "date", "tod", "datetime", "duration",
+ "oid-iri", "rel-oid-iri",
};
#ifdef DEBUG_DER
@@ -181,8 +191,10 @@ getlength(const uint8_t *c, size_t *p, s
size_t len;
int is_onebyte_result;
- if (*p >= l)
+ if (*p >= l) {
+ DPRINTF(("%s:[1] %zu >= %zu\n", __func__, *p, l));
return DER_BAD;
+ }
/*
* Digits can either be 0b0 followed by the result, or 0b1
@@ -191,8 +203,10 @@ getlength(const uint8_t *c, size_t *p, s
*/
is_onebyte_result = (c[*p] & 0x80) == 0;
digits = c[(*p)++] & 0x7f;
- if (*p + digits >= l)
+ if (*p + digits >= l) {
+ DPRINTF(("%s:[2] %zu + %u >= %zu\n", __func__, *p, digits, l));
return DER_BAD;
+ }
if (is_onebyte_result)
return digits;
@@ -205,15 +219,18 @@ getlength(const uint8_t *c, size_t *p, s
for (i = 0; i < digits; i++)
len = (len << 8) | c[(*p)++];
- if (len > UINT32_MAX - *p || *p + len >= l)
+ if (len > UINT32_MAX - *p || *p + len > l) {
+ DPRINTF(("%s:[3] bad len %zu + %zu >= %zu\n",
+ __func__, *p, len, l));
return DER_BAD;
+ }
return CAST(uint32_t, len);
}
static const char *
der_tag(char *buf, size_t len, uint32_t tag)
{
- if (tag < DER_TAG_LONG)
+ if (tag < DER_TAG_LAST)
strlcpy(buf, der__tag[tag], len);
else
snprintf(buf, len, "%#x", tag);
@@ -229,8 +246,13 @@ der_data(char *buf, size_t blen, uint32_
case DER_TAG_PRINTABLE_STRING:
case DER_TAG_UTF8_STRING:
case DER_TAG_IA5_STRING:
- case DER_TAG_UTCTIME:
return snprintf(buf, blen, "%.*s", len, RCAST(const char *, q));
+ case DER_TAG_UTCTIME:
+ if (len < 12)
+ break;
+ return snprintf(buf, blen,
+ "20%c%c-%c%c-%c%c %c%c:%c%c:%c%c GMT", d[0], d[1], d[2],
+ d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10], d[11]);
default:
break;
}
@@ -249,14 +271,18 @@ der_offs(struct magic_set *ms, struct ma
const uint8_t *b = RCAST(const uint8_t *, ms->search.s);
size_t offs = 0, len = ms->search.s_len ? ms->search.s_len : nbytes;
- if (gettag(b, &offs, len) == DER_BAD)
+ if (gettag(b, &offs, len) == DER_BAD) {
+ DPRINTF(("%s: bad tag 1\n", __func__));
return -1;
+ }
DPRINTF(("%s1: %d %" SIZE_T_FORMAT "u %u\n", __func__, ms->offset,
offs, m->offset));
uint32_t tlen = getlength(b, &offs, len);
- if (tlen == DER_BAD)
+ if (tlen == DER_BAD) {
+ DPRINTF(("%s: bad tag 2\n", __func__));
return -1;
+ }
DPRINTF(("%s2: %d %" SIZE_T_FORMAT "u %u\n", __func__, ms->offset,
offs, tlen));
@@ -286,13 +312,22 @@ der_cmp(struct magic_set *ms, struct mag
uint32_t tag, tlen;
char buf[128];
+ DPRINTF(("%s: compare %zu bytes\n", __func__, len));
+
tag = gettag(b, &offs, len);
- if (tag == DER_BAD)
+ if (tag == DER_BAD) {
+ DPRINTF(("%s: bad tag 1\n", __func__));
return -1;
+ }
+
+ DPRINTF(("%s1: %d %" SIZE_T_FORMAT "u %u\n", __func__, ms->offset,
+ offs, m->offset));
tlen = getlength(b, &offs, len);
- if (tlen == DER_BAD)
+ if (tlen == DER_BAD) {
+ DPRINTF(("%s: bad tag 2\n", __func__));
return -1;
+ }
der_tag(buf, sizeof(buf), tag);
if ((ms->flags & MAGIC_DEBUG) != 0)
@@ -348,6 +383,8 @@ printtag(uint32_t tag, const void *q, ui
switch (tag) {
case DER_TAG_PRINTABLE_STRING:
case DER_TAG_UTF8_STRING:
+ case DER_TAG_IA5_STRING:
+ case DER_TAG_UTCTIME:
printf("%.*s\n", len, (const char *)q);
return;
default:
@@ -371,8 +408,8 @@ printdata(size_t level, const void *v, s
uint8_t c = getclass(p[x]);
uint8_t t = gettype(p[x]);
ox = x;
- if (x != 0)
- printf("%.2x %.2x %.2x\n", p[x - 1], p[x], p[x + 1]);
+// if (x != 0)
+// printf("%.2x %.2x %.2x\n", p[x - 1], p[x], p[x + 1]);
uint32_t tag = gettag(p, &x, ep - p + x);
if (p + x >= ep)
break;
Index: src/external/bsd/file/dist/src/file.c
diff -u src/external/bsd/file/dist/src/file.c:1.14 src/external/bsd/file/dist/src/file.c:1.15
--- src/external/bsd/file/dist/src/file.c:1.14 Mon Dec 16 21:31:05 2019
+++ src/external/bsd/file/dist/src/file.c Sun Jun 14 20:37:24 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: file.c,v 1.14 2019/12/17 02:31:05 christos Exp $ */
+/* $NetBSD: file.c,v 1.15 2020/06/15 00:37:24 christos Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@@ -35,9 +35,9 @@
#ifndef lint
#if 0
-FILE_RCSID("@(#)$File: file.c,v 1.184 2019/08/03 11:51:59 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.187 2020/06/07 17:38:30 christos Exp $")
#else
-__RCSID("$NetBSD: file.c,v 1.14 2019/12/17 02:31:05 christos Exp $");
+__RCSID("$NetBSD: file.c,v 1.15 2020/06/15 00:37:24 christos Exp $");
#endif
#endif /* lint */
@@ -89,7 +89,8 @@ int getopt_long(int, char * const *, con
"Usage: %s [-" FILE_FLAGS "] [--apple] [--extension] [--mime-encoding]\n" \
" [--mime-type] [-e <testname>] [-F <separator>] " \
" [-f <namefile>]\n" \
- " [-m <magicfiles>] [-P <parameter=value>] <file> ...\n" \
+ " [-m <magicfiles>] [-P <parameter=value>] [--exclude-quiet]\n" \
+ " <file> ...\n" \
" %s -C [-m <magicfiles>]\n" \
" %s [--help]\n"
@@ -106,9 +107,10 @@ private const struct option long_options
#define OPT_EXTENSIONS 3
#define OPT_MIME_TYPE 4
#define OPT_MIME_ENCODING 5
-#define OPT(shortname, longname, opt, def, doc) \
+#define OPT_EXCLUDE_QUIET 6
+#define OPT(shortname, longname, opt, def, doc) \
{longname, opt, NULL, shortname},
-#define OPT_LONGONLY(longname, opt, def, doc, id) \
+#define OPT_LONGONLY(longname, opt, def, doc, id) \
{longname, opt, NULL, id},
#include "file_opts.h"
#undef OPT
@@ -139,14 +141,23 @@ private struct {
int tag;
size_t value;
int set;
+ size_t def;
+ const char *desc;
} pm[] = {
- { "indir", MAGIC_PARAM_INDIR_MAX, 0, 0 },
- { "name", MAGIC_PARAM_NAME_MAX, 0, 0 },
- { "elf_phnum", MAGIC_PARAM_ELF_PHNUM_MAX, 0, 0 },
- { "elf_shnum", MAGIC_PARAM_ELF_SHNUM_MAX, 0, 0 },
- { "elf_notes", MAGIC_PARAM_ELF_NOTES_MAX, 0, 0 },
- { "regex", MAGIC_PARAM_REGEX_MAX, 0, 0 },
- { "bytes", MAGIC_PARAM_BYTES_MAX, 0, 0 },
+ { "bytes", MAGIC_PARAM_BYTES_MAX, 0, 0, FILE_BYTES_MAX,
+ "max bytes to look inside file" },
+ { "elf_notes", MAGIC_PARAM_ELF_NOTES_MAX, 0, 0, FILE_ELF_NOTES_MAX,
+ "max ELF notes processed" },
+ { "elf_phnum", MAGIC_PARAM_ELF_PHNUM_MAX, 0, 0, FILE_ELF_PHNUM_MAX,
+ "max ELF prog sections processed" },
+ { "elf_shnum", MAGIC_PARAM_ELF_SHNUM_MAX, 0, 0, FILE_ELF_SHNUM_MAX,
+ "max ELF sections processed" },
+ { "indir", MAGIC_PARAM_INDIR_MAX, 0, 0, FILE_INDIR_MAX,
+ "recursion limit for indirection" },
+ { "name", MAGIC_PARAM_NAME_MAX, 0, 0, FILE_NAME_MAX,
+ "use limit for name/use magic" },
+ { "regex", MAGIC_PARAM_REGEX_MAX, 0, 0, FILE_REGEX_MAX,
+ "length limit for REGEX searches" },
};
private int posixly;
@@ -243,13 +254,15 @@ main(int argc, char *argv[])
flags |= MAGIC_ERROR;
break;
case 'e':
+ case OPT_EXCLUDE_QUIET:
for (i = 0; i < __arraycount(nv); i++)
if (strcmp(nv[i].name, optarg) == 0)
break;
- if (i == __arraycount(nv))
- errflg++;
- else
+ if (i == __arraycount(nv)) {
+ if (c != OPT_EXCLUDE_QUIET)
+ errflg++;
+ } else
flags |= nv[i].value;
break;
@@ -615,10 +628,10 @@ private void
docprint(const char *opts, int def)
{
size_t i;
- int comma;
+ int comma, pad;
char *sp, *p;
- p = strstr(opts, "%o");
+ p = strchr(opts, '%');
if (p == NULL) {
fprintf(stdout, "%s", opts);
defprint(def);
@@ -629,17 +642,34 @@ docprint(const char *opts, int def)
continue;
fprintf(stdout, "%.*s", CAST(int, p - opts), opts);
+ pad = (int)CAST(int, p - sp - 1);
- comma = 0;
- for (i = 0; i < __arraycount(nv); i++) {
- fprintf(stdout, "%s%s", comma++ ? ", " : "", nv[i].name);
- if (i && i % 5 == 0 && i != __arraycount(nv) - 1) {
- fprintf(stdout, ",\n%*s", CAST(int, p - sp - 1), "");
- comma = 0;
+ switch (*++p) {
+ case 'e':
+ comma = 0;
+ for (i = 0; i < __arraycount(nv); i++) {
+ fprintf(stdout, "%s%s", comma++ ? ", " : "", nv[i].name);
+ if (i && i % 5 == 0 && i != __arraycount(nv) - 1) {
+ fprintf(stdout, ",\n%*s", pad, "");
+ comma = 0;
+ }
+ }
+ break;
+ case 'P':
+ for (i = 0; i < __arraycount(pm); i++) {
+ fprintf(stdout, "%9s %7zu %s", pm[i].name, pm[i].def,
+ pm[i].desc);
+ if (i != __arraycount(pm) - 1)
+ fprintf(stdout, "\n%*s", pad, "");
}
+ break;
+ default:
+ file_errx(EXIT_FAILURE, "Unknown escape `%c' in long options",
+ *p);
+ break;
}
+ fprintf(stdout, "%s", opts + (p - opts) + 1);
- fprintf(stdout, "%s", opts + (p - opts) + 2);
}
private void
@@ -652,7 +682,7 @@ help(void)
#define OPT(shortname, longname, opt, def, doc) \
fprintf(stdout, " -%c, --" longname, shortname), \
docprint(doc, def);
-#define OPT_LONGONLY(longname, opt, def, doc, id) \
+#define OPT_LONGONLY(longname, opt, def, doc, id) \
fprintf(stdout, " --" longname), \
docprint(doc, def);
#include "file_opts.h"
@@ -686,7 +716,10 @@ file_err(int e, const char *fmt, ...)
fprintf(stderr, "%s: ", file_progname);
vfprintf(stderr, fmt, ap);
va_end(ap);
- fprintf(stderr, " (%s)\n", strerror(se));
+ if (se)
+ fprintf(stderr, " (%s)\n", strerror(se));
+ else
+ fputc('\n', stderr);
exit(e);
}
@@ -713,7 +746,10 @@ file_warn(const char *fmt, ...)
fprintf(stderr, "%s: ", file_progname);
vfprintf(stderr, fmt, ap);
va_end(ap);
- fprintf(stderr, " (%s)\n", strerror(se));
+ if (se)
+ fprintf(stderr, " (%s)\n", strerror(se));
+ else
+ fputc('\n', stderr);
errno = se;
}
Index: src/external/bsd/file/dist/src/magic.c
diff -u src/external/bsd/file/dist/src/magic.c:1.14 src/external/bsd/file/dist/src/magic.c:1.15
--- src/external/bsd/file/dist/src/magic.c:1.14 Wed May 22 13:26:05 2019
+++ src/external/bsd/file/dist/src/magic.c Sun Jun 14 20:37:24 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: magic.c,v 1.14 2019/05/22 17:26:05 christos Exp $ */
+/* $NetBSD: magic.c,v 1.15 2020/06/15 00:37:24 christos Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
@@ -36,9 +36,9 @@
#ifndef lint
#if 0
-FILE_RCSID("@(#)$File: magic.c,v 1.111 2019/05/07 02:27:11 christos Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.112 2020/06/08 19:44:10 christos Exp $")
#else
-__RCSID("$NetBSD: magic.c,v 1.14 2019/05/22 17:26:05 christos Exp $");
+__RCSID("$NetBSD: magic.c,v 1.15 2020/06/15 00:37:24 christos Exp $");
#endif
#endif /* lint */
@@ -469,8 +469,7 @@ file_or_fd(struct magic_set *ms, const c
}
if (fd != -1) {
- if (!okstat)
- okstat = fstat(fd, &sb) == 0;
+ okstat = fstat(fd, &sb) == 0;
if (okstat && S_ISFIFO(sb.st_mode))
ispipe = 1;
if (inname == NULL)
Index: src/external/bsd/file/dist/src/print.c
diff -u src/external/bsd/file/dist/src/print.c:1.14 src/external/bsd/file/dist/src/print.c:1.15
--- src/external/bsd/file/dist/src/print.c:1.14 Wed May 22 13:26:05 2019
+++ src/external/bsd/file/dist/src/print.c Sun Jun 14 20:37:24 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: print.c,v 1.14 2019/05/22 17:26:05 christos Exp $ */
+/* $NetBSD: print.c,v 1.15 2020/06/15 00:37:24 christos Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@@ -35,9 +35,9 @@
#ifndef lint
#if 0
-FILE_RCSID("@(#)$File: print.c,v 1.85 2019/03/12 20:43:05 christos Exp $")
+FILE_RCSID("@(#)$File: print.c,v 1.88 2020/05/09 18:57:15 christos Exp $")
#else
-__RCSID("$NetBSD: print.c,v 1.14 2019/05/22 17:26:05 christos Exp $");
+__RCSID("$NetBSD: print.c,v 1.15 2020/06/15 00:37:24 christos Exp $");
#endif
#endif /* lint */
@@ -56,7 +56,7 @@ protected void
file_mdump(struct magic *m)
{
static const char optyp[] = { FILE_OPS };
- char tbuf[26];
+ char tbuf[256];
(void) fprintf(stderr, "%u: %.*s %u", m->lineno,
(m->cont_level & 7) + 1, ">>>>>>>>", m->offset);
@@ -145,6 +145,7 @@ file_mdump(struct magic *m)
case FILE_BEQUAD:
case FILE_LEQUAD:
case FILE_QUAD:
+ case FILE_OFFSET:
(void) fprintf(stderr, "%" INT64_T_FORMAT "d",
CAST(long long, m->value.q));
break;
@@ -162,32 +163,35 @@ file_mdump(struct magic *m)
case FILE_BEDATE:
case FILE_MEDATE:
(void)fprintf(stderr, "%s,",
- file_fmttime(m->value.l, 0, tbuf));
+ file_fmttime(tbuf, sizeof(tbuf), m->value.l, 0));
break;
case FILE_LDATE:
case FILE_LELDATE:
case FILE_BELDATE:
case FILE_MELDATE:
(void)fprintf(stderr, "%s,",
- file_fmttime(m->value.l, FILE_T_LOCAL, tbuf));
+ file_fmttime(tbuf, sizeof(tbuf), m->value.l,
+ FILE_T_LOCAL));
break;
case FILE_QDATE:
case FILE_LEQDATE:
case FILE_BEQDATE:
(void)fprintf(stderr, "%s,",
- file_fmttime(m->value.q, 0, tbuf));
+ file_fmttime(tbuf, sizeof(tbuf), m->value.q, 0));
break;
case FILE_QLDATE:
case FILE_LEQLDATE:
case FILE_BEQLDATE:
(void)fprintf(stderr, "%s,",
- file_fmttime(m->value.q, FILE_T_LOCAL, tbuf));
+ file_fmttime(tbuf, sizeof(tbuf), m->value.q,
+ FILE_T_LOCAL));
break;
case FILE_QWDATE:
case FILE_LEQWDATE:
case FILE_BEQWDATE:
(void)fprintf(stderr, "%s,",
- file_fmttime(m->value.q, FILE_T_WINDOWS, tbuf));
+ file_fmttime(tbuf, sizeof(tbuf), m->value.q,
+ FILE_T_WINDOWS));
break;
case FILE_FLOAT:
case FILE_BEFLOAT:
@@ -207,6 +211,12 @@ file_mdump(struct magic *m)
case FILE_DER:
(void) fprintf(stderr, "'%s'", m->value.s);
break;
+ case FILE_GUID:
+ (void) file_print_guid(tbuf, sizeof(tbuf),
+ m->value.guid);
+ (void) fprintf(stderr, "%s", tbuf);
+ break;
+
default:
(void) fprintf(stderr, "*bad type %d*", m->type);
break;
@@ -236,7 +246,7 @@ file_magwarn(struct magic_set *ms, const
}
protected const char *
-file_fmttime(uint64_t v, int flags, char *buf)
+file_fmttime(char *buf, size_t bsize, uint64_t v, int flags)
{
char *pp;
time_t t;
@@ -266,5 +276,6 @@ file_fmttime(uint64_t v, int flags, char
pp[strcspn(pp, "\n")] = '\0';
return pp;
out:
- return strcpy(buf, "*Invalid time*");
+ strlcpy(buf, "*Invalid time*", bsize);
+ return buf;
}
Index: src/external/bsd/file/dist/src/funcs.c
diff -u src/external/bsd/file/dist/src/funcs.c:1.17 src/external/bsd/file/dist/src/funcs.c:1.18
--- src/external/bsd/file/dist/src/funcs.c:1.17 Mon Dec 16 21:31:05 2019
+++ src/external/bsd/file/dist/src/funcs.c Sun Jun 14 20:37:24 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: funcs.c,v 1.17 2019/12/17 02:31:05 christos Exp $ */
+/* $NetBSD: funcs.c,v 1.18 2020/06/15 00:37:24 christos Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
@@ -30,9 +30,9 @@
#ifndef lint
#if 0
-FILE_RCSID("@(#)$File: funcs.c,v 1.108 2019/11/09 00:35:46 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.115 2020/02/20 15:50:20 christos Exp $")
#else
-__RCSID("$NetBSD: funcs.c,v 1.17 2019/12/17 02:31:05 christos Exp $");
+__RCSID("$NetBSD: funcs.c,v 1.18 2020/06/15 00:37:24 christos Exp $");
#endif
#endif /* lint */
@@ -54,6 +54,77 @@ __RCSID("$NetBSD: funcs.c,v 1.17 2019/12
#define SIZE_MAX ((size_t)~0)
#endif
+protected char *
+file_copystr(char *buf, size_t blen, size_t width, const char *str)
+{
+ if (++width > blen)
+ width = blen;
+ strlcpy(buf, str, width);
+ return buf;
+}
+
+private void
+file_clearbuf(struct magic_set *ms)
+{
+ free(ms->o.buf);
+ ms->o.buf = NULL;
+ ms->o.blen = 0;
+}
+
+private int
+file_checkfield(char *msg, size_t mlen, const char *what, const char **pp)
+{
+ const char *p = *pp;
+ int fw = 0;
+
+ while (*p && isdigit((unsigned char)*p))
+ fw = fw * 10 + (*p++ - '0');
+
+ *pp = p;
+
+ if (fw < 1024)
+ return 1;
+ if (msg)
+ snprintf(msg, mlen, "field %s too large: %d", what, fw);
+
+ return 0;
+}
+
+protected int
+file_checkfmt(char *msg, size_t mlen, const char *fmt)
+{
+ for (const char *p = fmt; *p; p++) {
+ if (*p != '%')
+ continue;
+ if (*++p == '%')
+ continue;
+ // Skip uninteresting.
+ while (strchr("0.'+- ", *p) != NULL)
+ p++;
+ if (*p == '*') {
+ if (msg)
+ snprintf(msg, mlen, "* not allowed in format");
+ return -1;
+ }
+
+ if (!file_checkfield(msg, mlen, "width", &p))
+ return -1;
+
+ if (*p == '.') {
+ p++;
+ if (!file_checkfield(msg, mlen, "precision", &p))
+ return -1;
+ }
+
+ if (!isalpha((unsigned char)*p)) {
+ if (msg)
+ snprintf(msg, mlen, "bad format char: %c", *p);
+ return -1;
+ }
+ }
+ return 0;
+}
+
/*
* Like printf, only we append to a buffer.
*/
@@ -62,12 +133,26 @@ file_vprintf(struct magic_set *ms, const
{
int len;
char *buf, *newstr;
+ char tbuf[1024];
if (ms->event_flags & EVENT_HAD_ERR)
return 0;
+
+ if (file_checkfmt(tbuf, sizeof(tbuf), fmt)) {
+ file_clearbuf(ms);
+ file_error(ms, 0, "Bad magic format `%s' (%s)", fmt, tbuf);
+ return -1;
+ }
+
len = vasprintf(&buf, fmt, ap);
- if (len < 0)
- goto out;
+ if (len < 0 || (size_t)len > 1024 || len + ms->o.blen > 1024 * 1024) {
+ size_t blen = ms->o.blen;
+ free(buf);
+ file_clearbuf(ms);
+ file_error(ms, 0, "Output buffer space exceeded %d+%zu", len,
+ blen);
+ return -1;
+ }
if (ms->o.buf != NULL) {
len = asprintf(&newstr, "%s%s", ms->o.buf, buf);
@@ -78,9 +163,11 @@ file_vprintf(struct magic_set *ms, const
buf = newstr;
}
ms->o.buf = buf;
+ ms->o.blen = len;
return 0;
out:
- fprintf(stderr, "vasprintf failed (%s)", strerror(errno));
+ file_clearbuf(ms);
+ file_error(ms, errno, "vasprintf failed");
return -1;
}
@@ -109,8 +196,7 @@ file_error_core(struct magic_set *ms, in
if (ms->event_flags & EVENT_HAD_ERR)
return;
if (lineno != 0) {
- free(ms->o.buf);
- ms->o.buf = NULL;
+ file_clearbuf(ms);
(void)file_printf(ms, "line %" SIZE_T_FORMAT "u:", lineno);
}
if (ms->o.buf && *ms->o.buf)
@@ -399,10 +485,7 @@ file_reset(struct magic_set *ms, int che
file_error(ms, 0, "no magic files loaded");
return -1;
}
- if (ms->o.buf) {
- free(ms->o.buf);
- ms->o.buf = NULL;
- }
+ file_clearbuf(ms);
if (ms->o.pbuf) {
free(ms->o.pbuf);
ms->o.pbuf = NULL;
@@ -524,7 +607,7 @@ file_check_mem(struct magic_set *ms, uns
protected size_t
file_printedlen(const struct magic_set *ms)
{
- return ms->o.buf == NULL ? 0 : strlen(ms->o.buf);
+ return ms->o.blen;
}
protected int
@@ -620,9 +703,11 @@ file_push_buffer(struct magic_set *ms)
return NULL;
pb->buf = ms->o.buf;
+ pb->blen = ms->o.blen;
pb->offset = ms->offset;
ms->o.buf = NULL;
+ ms->o.blen = 0;
ms->offset = 0;
return pb;
@@ -642,6 +727,7 @@ file_pop_buffer(struct magic_set *ms, fi
rbuf = ms->o.buf;
ms->o.buf = pb->buf;
+ ms->o.blen = pb->blen;
ms->offset = pb->offset;
free(pb);
@@ -673,3 +759,34 @@ file_printable(char *buf, size_t bufsiz,
*ptr = '\0';
return buf;
}
+
+struct guid {
+ uint32_t data1;
+ uint16_t data2;
+ uint16_t data3;
+ uint8_t data4[8];
+};
+
+protected int
+file_parse_guid(const char *s, uint64_t *guid)
+{
+ struct guid *g = CAST(struct guid *, CAST(void *, guid));
+ return sscanf(s,
+ "%8x-%4hx-%4hx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
+ &g->data1, &g->data2, &g->data3, &g->data4[0], &g->data4[1],
+ &g->data4[2], &g->data4[3], &g->data4[4], &g->data4[5],
+ &g->data4[6], &g->data4[7]) == 11 ? 0 : -1;
+}
+
+protected int
+file_print_guid(char *str, size_t len, const uint64_t *guid)
+{
+ const struct guid *g = CAST(const struct guid *,
+ CAST(const void *, guid));
+
+ return snprintf(str, len, "%.8X-%.4hX-%.4hX-%.2hhX%.2hhX-"
+ "%.2hhX%.2hhX%.2hhX%.2hhX%.2hhX%.2hhX",
+ g->data1, g->data2, g->data3, g->data4[0], g->data4[1],
+ g->data4[2], g->data4[3], g->data4[4], g->data4[5],
+ g->data4[6], g->data4[7]);
+}
Index: src/external/bsd/file/dist/src/is_csv.c
diff -u src/external/bsd/file/dist/src/is_csv.c:1.1.1.1 src/external/bsd/file/dist/src/is_csv.c:1.2
--- src/external/bsd/file/dist/src/is_csv.c:1.1.1.1 Mon Dec 16 21:23:53 2019
+++ src/external/bsd/file/dist/src/is_csv.c Sun Jun 14 20:37:24 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: is_csv.c,v 1.1.1.1 2019/12/17 02:23:53 christos Exp $ */
+/* $NetBSD: is_csv.c,v 1.2 2020/06/15 00:37:24 christos Exp $ */
/*-
* Copyright (c) 2019 Christos Zoulas
@@ -37,7 +37,7 @@
#if 0
FILE_RCSID("@(#)$File: is_csv.c,v 1.4 2019/06/26 20:31:31 christos Exp $")
#else
-__RCSID("$NetBSD: is_csv.c,v 1.1.1.1 2019/12/17 02:23:53 christos Exp $");
+__RCSID("$NetBSD: is_csv.c,v 1.2 2020/06/15 00:37:24 christos Exp $");
#endif
#endif
@@ -100,8 +100,7 @@ csv_parse(const unsigned char *uc, const
size_t nf = 0, tf = 0, nl = 0;
while (uc < ue) {
- unsigned char c;
- switch (c = *uc++) {
+ switch (*uc++) {
case '"':
// Eat until the matching quote
uc = eatquote(uc, ue);
Index: src/external/bsd/file/dist/src/is_json.c
diff -u src/external/bsd/file/dist/src/is_json.c:1.3 src/external/bsd/file/dist/src/is_json.c:1.4
--- src/external/bsd/file/dist/src/is_json.c:1.3 Wed May 22 13:26:05 2019
+++ src/external/bsd/file/dist/src/is_json.c Sun Jun 14 20:37:24 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: is_json.c,v 1.3 2019/05/22 17:26:05 christos Exp $ */
+/* $NetBSD: is_json.c,v 1.4 2020/06/15 00:37:24 christos Exp $ */
/*-
* Copyright (c) 2018 Christos Zoulas
@@ -35,9 +35,9 @@
#ifndef lint
#if 0
-FILE_RCSID("@(#)$File: is_json.c,v 1.13 2019/03/02 01:08:10 christos Exp $")
+FILE_RCSID("@(#)$File: is_json.c,v 1.15 2020/06/07 19:05:47 christos Exp $")
#else
-__RCSID("$NetBSD: is_json.c,v 1.3 2019/05/22 17:26:05 christos Exp $");
+__RCSID("$NetBSD: is_json.c,v 1.4 2020/06/15 00:37:24 christos Exp $");
#endif
#endif
@@ -162,6 +162,7 @@ json_parse_string(const unsigned char **
}
case '"':
*ucp = uc;
+ DPRINTF("Good string: ", uc, *ucp);
return 1;
default:
continue;
@@ -178,23 +179,24 @@ json_parse_array(const unsigned char **u
size_t *st, size_t lvl)
{
const unsigned char *uc = *ucp;
- int more = 0; /* Array has more than 1 element */
DPRINTF("Parse array: ", uc, *ucp);
while (uc < ue) {
+ if (*uc == ']')
+ goto done;
if (!json_parse(&uc, ue, st, lvl + 1))
goto out;
if (uc == ue)
goto out;
switch (*uc) {
case ',':
- more++;
uc++;
continue;
case ']':
- if (more)
- st[JSON_ARRAYN]++;
+ done:
+ st[JSON_ARRAYN]++;
*ucp = uc + 1;
+ DPRINTF("Good array: ", uc, *ucp);
return 1;
default:
goto out;
@@ -216,6 +218,10 @@ json_parse_object(const unsigned char **
uc = json_skip_space(uc, ue);
if (uc == ue)
goto out;
+ if (*uc == '}') {
+ uc++;
+ goto done;
+ }
if (*uc++ != '"') {
DPRINTF("not string", uc, *ucp);
goto out;
@@ -242,6 +248,7 @@ json_parse_object(const unsigned char **
case ',':
continue;
case '}': /* { */
+ done:
*ucp = uc;
DPRINTF("Good object: ", uc, *ucp);
return 1;
Index: src/external/bsd/file/dist/src/readelf.c
diff -u src/external/bsd/file/dist/src/readelf.c:1.23 src/external/bsd/file/dist/src/readelf.c:1.24
--- src/external/bsd/file/dist/src/readelf.c:1.23 Tue Dec 17 03:02:00 2019
+++ src/external/bsd/file/dist/src/readelf.c Sun Jun 14 20:37:24 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: readelf.c,v 1.23 2019/12/17 08:02:00 martin Exp $ */
+/* $NetBSD: readelf.c,v 1.24 2020/06/15 00:37:24 christos Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
@@ -30,9 +30,9 @@
#ifndef lint
#if 0
-FILE_RCSID("@(#)$File: readelf.c,v 1.168 2019/12/16 03:49:19 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.173 2020/06/07 22:12:54 christos Exp $")
#else
-__RCSID("$NetBSD: readelf.c,v 1.23 2019/12/17 08:02:00 martin Exp $");
+__RCSID("$NetBSD: readelf.c,v 1.24 2020/06/15 00:37:24 christos Exp $");
#endif
#endif
@@ -73,6 +73,8 @@ private uint64_t getu64(int, uint64_t);
private int
toomany(struct magic_set *ms, const char *name, uint16_t num)
{
+ if (ms->flags & MAGIC_MIME)
+ return 1;
if (file_printf(ms, ", too many %s (%u)", name, num) == -1)
return -1;
return 1;
@@ -361,6 +363,9 @@ dophn_core(struct magic_set *ms, int cla
off_t ph_off = off;
int ph_num = num;
+ if (ms->flags & MAGIC_MIME)
+ return 0;
+
if (num == 0) {
if (file_printf(ms, ", no program header") == -1)
return -1;
@@ -574,8 +579,10 @@ do_bid_note(struct magic_set *ms, unsign
}
if (namesz == 4 && strcmp(RCAST(char *, &nbuf[noff]), "Go") == 0 &&
type == NT_GO_BUILD_ID && descsz < 128) {
- if (file_printf(ms, ", Go BuildID=%.*s",
- CAST(int, descsz), RCAST(char *, &nbuf[doff])) == -1)
+ char buf[256];
+ if (file_printf(ms, ", Go BuildID=%s",
+ file_copystr(buf, sizeof(buf), descsz,
+ RCAST(const char *, &nbuf[doff]))) == -1)
return -1;
return 1;
}
@@ -727,6 +734,7 @@ do_core_note(struct magic_set *ms, unsig
size_t noff, size_t doff, int *flags, size_t size, int clazz)
{
#ifdef ELFCORE
+ char buf[256];
const char *name = RCAST(const char *, &nbuf[noff]);
int os_style = -1;
@@ -907,8 +915,10 @@ do_core_note(struct magic_set *ms, unsig
*/
while (cp > cname && isspace(cp[-1]))
cp--;
- if (file_printf(ms, ", from '%.*s'",
- CAST(int, cp - cname), cname) == -1)
+ if (file_printf(ms, ", from '%s'",
+ file_copystr(buf, sizeof(buf),
+ CAST(size_t, cp - cname),
+ CAST(const char *, cname))) == -1)
return -1;
*flags |= FLAGS_DID_CORE;
return 1;
@@ -1134,6 +1144,7 @@ donote(struct magic_set *ms, void *vbuf,
Elf64_Nhdr nh64;
size_t noff, doff;
uint32_t namesz, descsz;
+ char buf[256];
unsigned char *nbuf = CAST(unsigned char *, vbuf);
if (*notecount == 0)
@@ -1261,7 +1272,8 @@ donote(struct magic_set *ms, void *vbuf,
str = RCAST(const char *, &nbuf[doff]);
descw = CAST(int, descsz);
*flags |= flag;
- file_printf(ms, ", %s: %.*s", tag, descw, str);
+ file_printf(ms, ", %s: %s", tag,
+ file_copystr(buf, sizeof(buf), descw, str));
return offset;
}
@@ -1334,6 +1346,9 @@ doshn(struct magic_set *ms, int clazz, i
char name[50];
ssize_t namesize;
+ if (ms->flags & MAGIC_MIME)
+ return 0;
+
if (num == 0) {
if (file_printf(ms, ", no section header") == -1)
return -1;
@@ -1645,6 +1660,7 @@ dophn_exec(struct magic_set *ms, int cla
switch (xph_type) {
case PT_DYNAMIC:
doread = 1;
+ linking_style = "dynamically";
break;
case PT_NOTE:
if (sh_num) /* Did this through section headers */
@@ -1659,7 +1675,6 @@ dophn_exec(struct magic_set *ms, int cla
}
/*FALLTHROUGH*/
case PT_INTERP:
- linking_style = "dynamically";
doread = 1;
break;
default:
@@ -1696,9 +1711,13 @@ dophn_exec(struct magic_set *ms, int cla
if (offset == 0)
break;
}
+ if (ms->flags & MAGIC_MIME)
+ continue;
break;
case PT_INTERP:
+ if (ms->flags & MAGIC_MIME)
+ continue;
if (bufsize && nbuf[0]) {
nbuf[bufsize - 1] = '\0';
memcpy(interp, nbuf, CAST(size_t, bufsize));
@@ -1706,6 +1725,8 @@ dophn_exec(struct magic_set *ms, int cla
strlcpy(interp, "*empty*", sizeof(interp));
break;
case PT_NOTE:
+ if (ms->flags & MAGIC_MIME)
+ return 0;
/*
* This is a PT_NOTE section; loop through all the notes
* in the section.
@@ -1722,9 +1743,13 @@ dophn_exec(struct magic_set *ms, int cla
}
break;
default:
+ if (ms->flags & MAGIC_MIME)
+ continue;
break;
}
}
+ if (ms->flags & MAGIC_MIME)
+ return 0;
if (file_printf(ms, ", %s linked", linking_style)
== -1)
return -1;
@@ -1757,7 +1782,7 @@ file_tryelf(struct magic_set *ms, const
Elf64_Ehdr elf64hdr;
uint16_t type, phnum, shnum, notecount;
- if (ms->flags & (MAGIC_MIME|MAGIC_APPLE|MAGIC_EXTENSION))
+ if (ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION))
return 0;
/*
* ELF executables have multiple section headers in arbitrary
Index: src/external/bsd/file/dist/src/softmagic.c
diff -u src/external/bsd/file/dist/src/softmagic.c:1.22 src/external/bsd/file/dist/src/softmagic.c:1.23
--- src/external/bsd/file/dist/src/softmagic.c:1.22 Wed May 22 13:26:05 2019
+++ src/external/bsd/file/dist/src/softmagic.c Sun Jun 14 20:37:24 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: softmagic.c,v 1.22 2019/05/22 17:26:05 christos Exp $ */
+/* $NetBSD: softmagic.c,v 1.23 2020/06/15 00:37:24 christos Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@@ -35,9 +35,9 @@
#ifndef lint
#if 0
-FILE_RCSID("@(#)$File: softmagic.c,v 1.286 2019/05/17 02:24:59 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.299 2020/06/07 21:58:01 christos Exp $")
#else
-__RCSID("$NetBSD: softmagic.c,v 1.22 2019/05/22 17:26:05 christos Exp $");
+__RCSID("$NetBSD: softmagic.c,v 1.23 2020/06/15 00:37:24 christos Exp $");
#endif
#endif /* lint */
@@ -337,6 +337,13 @@ flush:
if (msetoffset(ms, m, &bb, b, offset, cont_level) == -1)
goto flush;
if (m->flag & OFFADD) {
+ if (cont_level == 0) {
+ if ((ms->flags & MAGIC_DEBUG) != 0)
+ fprintf(stderr,
+ "direct *zero*"
+ " cont_level\n");
+ return 0;
+ }
ms->offset +=
ms->c.li[cont_level - 1].off;
}
@@ -648,6 +655,7 @@ mprint(struct magic_set *ms, struct magi
case FILE_QUAD:
case FILE_BEQUAD:
case FILE_LEQUAD:
+ case FILE_OFFSET:
v = file_signextend(ms, m, p->q);
switch (check_fmt(ms, desc)) {
case -1:
@@ -705,8 +713,12 @@ mprint(struct magic_set *ms, struct magi
sizeof(p->s) - (str - p->s))) == -1)
return -1;
- if (m->type == FILE_PSTRING)
- t += file_pstring_length_size(m);
+ if (m->type == FILE_PSTRING) {
+ size_t l = file_pstring_length_size(ms, m);
+ if (l == FILE_BADSIZE)
+ return -1;
+ t += l;
+ }
}
break;
@@ -715,7 +727,7 @@ mprint(struct magic_set *ms, struct magi
case FILE_LEDATE:
case FILE_MEDATE:
if (file_printf(ms, F(ms, desc, "%s"),
- file_fmttime(p->l, 0, tbuf)) == -1)
+ file_fmttime(tbuf, sizeof(tbuf), p->l, 0)) == -1)
return -1;
t = ms->offset + sizeof(uint32_t);
break;
@@ -725,7 +737,7 @@ mprint(struct magic_set *ms, struct magi
case FILE_LELDATE:
case FILE_MELDATE:
if (file_printf(ms, F(ms, desc, "%s"),
- file_fmttime(p->l, FILE_T_LOCAL, tbuf)) == -1)
+ file_fmttime(tbuf, sizeof(tbuf), p->l, FILE_T_LOCAL)) == -1)
return -1;
t = ms->offset + sizeof(uint32_t);
break;
@@ -734,7 +746,7 @@ mprint(struct magic_set *ms, struct magi
case FILE_BEQDATE:
case FILE_LEQDATE:
if (file_printf(ms, F(ms, desc, "%s"),
- file_fmttime(p->q, 0, tbuf)) == -1)
+ file_fmttime(tbuf, sizeof(tbuf), p->q, 0)) == -1)
return -1;
t = ms->offset + sizeof(uint64_t);
break;
@@ -743,7 +755,7 @@ mprint(struct magic_set *ms, struct magi
case FILE_BEQLDATE:
case FILE_LEQLDATE:
if (file_printf(ms, F(ms, desc, "%s"),
- file_fmttime(p->q, FILE_T_LOCAL, tbuf)) == -1)
+ file_fmttime(tbuf, sizeof(tbuf), p->q, FILE_T_LOCAL)) == -1)
return -1;
t = ms->offset + sizeof(uint64_t);
break;
@@ -752,7 +764,8 @@ mprint(struct magic_set *ms, struct magi
case FILE_BEQWDATE:
case FILE_LEQWDATE:
if (file_printf(ms, F(ms, desc, "%s"),
- file_fmttime(p->q, FILE_T_WINDOWS, tbuf)) == -1)
+ file_fmttime(tbuf, sizeof(tbuf), p->q, FILE_T_WINDOWS))
+ == -1)
return -1;
t = ms->offset + sizeof(uint64_t);
break;
@@ -841,6 +854,12 @@ mprint(struct magic_set *ms, struct magi
return -1;
t = ms->offset;
break;
+ case FILE_GUID:
+ (void) file_print_guid(buf, sizeof(buf), ms->ms_value.guid);
+ if (file_printf(ms, F(ms, desc, "%s"), buf) == -1)
+ return -1;
+ t = ms->offset;
+ break;
default:
file_magerror(ms, "invalid m->type (%d) in mprint()", m->type);
return -1;
@@ -891,9 +910,12 @@ moffset(struct magic_set *ms, struct mag
if (*m->value.s == '\0')
p->s[strcspn(p->s, "\r\n")] = '\0';
o = CAST(uint32_t, (ms->offset + strlen(p->s)));
- if (m->type == FILE_PSTRING)
- o += CAST(uint32_t,
- file_pstring_length_size(m));
+ if (m->type == FILE_PSTRING) {
+ size_t l = file_pstring_length_size(ms, m);
+ if (l == FILE_BADSIZE)
+ return -1;
+ o += CAST(uint32_t, l);
+ }
}
break;
@@ -953,23 +975,26 @@ moffset(struct magic_set *ms, struct mag
case FILE_CLEAR:
case FILE_DEFAULT:
case FILE_INDIRECT:
+ case FILE_OFFSET:
o = ms->offset;
break;
case FILE_DER:
- {
- o = der_offs(ms, m, nbytes);
- if (o == -1 || CAST(size_t, o) > nbytes) {
- if ((ms->flags & MAGIC_DEBUG) != 0) {
- (void)fprintf(stderr,
- "Bad DER offset %d nbytes=%"
- SIZE_T_FORMAT "u", o, nbytes);
- }
- *op = 0;
- return 0;
+ o = der_offs(ms, m, nbytes);
+ if (o == -1 || CAST(size_t, o) > nbytes) {
+ if ((ms->flags & MAGIC_DEBUG) != 0) {
+ (void)fprintf(stderr,
+ "Bad DER offset %d nbytes=%"
+ SIZE_T_FORMAT "u", o, nbytes);
}
- break;
+ *op = 0;
+ return 0;
}
+ break;
+
+ case FILE_GUID:
+ o = CAST(int32_t, (ms->offset + 2 * sizeof(uint64_t)));
+ break;
default:
o = 0;
@@ -1174,6 +1199,7 @@ mconvert(struct magic_set *ms, struct ma
case FILE_QDATE:
case FILE_QLDATE:
case FILE_QWDATE:
+ case FILE_OFFSET:
if (cvt_64(p, m) == -1)
goto out;
return 1;
@@ -1185,9 +1211,15 @@ mconvert(struct magic_set *ms, struct ma
return 1;
}
case FILE_PSTRING: {
- size_t sz = file_pstring_length_size(m);
- char *ptr1 = p->s, *ptr2 = ptr1 + sz;
- size_t len = file_pstring_get_length(m, ptr1);
+ char *ptr1, *ptr2;
+ size_t len, sz = file_pstring_length_size(ms, m);
+ if (sz == FILE_BADSIZE)
+ return 0;
+ ptr1 = p->s;
+ ptr2 = ptr1 + sz;
+ len = file_pstring_get_length(ms, m, ptr1);
+ if (len == FILE_BADSIZE)
+ return 0;
sz = sizeof(p->s) - sz; /* maximum length of string */
if (len >= sz) {
/*
@@ -1287,6 +1319,7 @@ mconvert(struct magic_set *ms, struct ma
case FILE_NAME:
case FILE_USE:
case FILE_DER:
+ case FILE_GUID:
return 1;
default:
file_magerror(ms, "invalid type %d in mconvert()", m->type);
@@ -1413,6 +1446,12 @@ mcopy(struct magic_set *ms, union VALUET
}
}
+ if (type == FILE_OFFSET) {
+ (void)memset(p, '\0', sizeof(*p));
+ p->q = offset;
+ return 0;
+ }
+
if (offset >= nbytes) {
(void)memset(p, '\0', sizeof(*p));
return 0;
@@ -1477,7 +1516,9 @@ private int
msetoffset(struct magic_set *ms, struct magic *m, struct buffer *bb,
const struct buffer *b, size_t o, unsigned int cont_level)
{
- if (m->offset < 0) {
+ int32_t offset;
+ if (m->flag & OFFNEGATIVE) {
+ offset = -m->offset;
if (cont_level > 0) {
if (m->flag & (OFFADD|INDIROFFADD))
goto normal;
@@ -1495,26 +1536,28 @@ msetoffset(struct magic_set *ms, struct
"u at level %u", o, cont_level);
return -1;
}
- if (CAST(size_t, -m->offset) > b->elen)
+ if (CAST(size_t, m->offset) > b->elen)
return -1;
buffer_init(bb, -1, NULL, b->ebuf, b->elen);
- ms->eoffset = ms->offset = CAST(int32_t, b->elen + m->offset);
+ ms->eoffset = ms->offset = CAST(int32_t, b->elen - m->offset);
} else {
+ offset = m->offset;
if (cont_level == 0) {
normal:
// XXX: Pass real fd, then who frees bb?
buffer_init(bb, -1, NULL, b->fbuf, b->flen);
- ms->offset = m->offset;
+ ms->offset = offset;
ms->eoffset = 0;
} else {
- ms->offset = ms->eoffset + m->offset;
+ ms->offset = ms->eoffset + offset;
}
}
if ((ms->flags & MAGIC_DEBUG) != 0) {
- fprintf(stderr, "bb=[%p,%" SIZE_T_FORMAT "u], %d [b=%p,%"
- SIZE_T_FORMAT "u], [o=%#x, c=%d]\n",
- bb->fbuf, bb->flen, ms->offset, b->fbuf, b->flen,
- m->offset, cont_level);
+ fprintf(stderr, "bb=[%p,%" SIZE_T_FORMAT "u,%"
+ SIZE_T_FORMAT "u], %d [b=%p,%"
+ SIZE_T_FORMAT "u,%" SIZE_T_FORMAT "u], [o=%#x, c=%d]\n",
+ bb->fbuf, bb->flen, bb->elen, ms->offset, b->fbuf,
+ b->flen, b->elen, offset, cont_level);
}
return 0;
}
@@ -1572,7 +1615,8 @@ mget(struct magic_set *ms, struct magic
if (m->in_op & FILE_OPINDIRECT) {
const union VALUETYPE *q = CAST(const union VALUETYPE *,
RCAST(const void *, s + offset + off));
- switch (cvt_flip(m->in_type, flip)) {
+ int op;
+ switch (op = cvt_flip(m->in_type, flip)) {
case FILE_BYTE:
if (OFFSET_OOB(nbytes, offset + off, 1))
return 0;
@@ -1626,7 +1670,9 @@ mget(struct magic_set *ms, struct magic
off = SEXT(sgn,64,LE64(q));
break;
default:
- abort();
+ if ((ms->flags & MAGIC_DEBUG) != 0)
+ fprintf(stderr, "bad op=%d\n", op);
+ return 0;
}
if ((ms->flags & MAGIC_DEBUG) != 0)
fprintf(stderr, "indirect offs=%jd\n", off);
@@ -1691,11 +1737,19 @@ mget(struct magic_set *ms, struct magic
offset = do_ops(m, SEXT(sgn,64,BE64(p)), off);
break;
default:
- abort();
+ if ((ms->flags & MAGIC_DEBUG) != 0)
+ fprintf(stderr, "bad in_type=%d\n", in_type);
+ return 0;
}
if (m->flag & INDIROFFADD) {
- offset += ms->c.li[cont_level-1].off;
+ if (cont_level == 0) {
+ if ((ms->flags & MAGIC_DEBUG) != 0)
+ fprintf(stderr,
+ "indirect *zero* cont_level\n");
+ return 0;
+ }
+ offset += ms->c.li[cont_level - 1].off;
if (offset == 0) {
if ((ms->flags & MAGIC_DEBUG) != 0)
fprintf(stderr,
@@ -1758,6 +1812,11 @@ mget(struct magic_set *ms, struct magic
return 0;
break;
+ case FILE_GUID:
+ if (OFFSET_OOB(nbytes, offset, 16))
+ return 0;
+ break;
+
case FILE_STRING:
case FILE_PSTRING:
case FILE_SEARCH:
@@ -1853,7 +1912,8 @@ mget(struct magic_set *ms, struct magic
}
private uint64_t
-file_strncmp(const char *s1, const char *s2, size_t len, uint32_t flags)
+file_strncmp(const char *s1, const char *s2, size_t len, size_t maxlen,
+ uint32_t flags)
{
/*
* Convert the source args to unsigned here so that (1) the
@@ -1863,7 +1923,9 @@ file_strncmp(const char *s1, const char
*/
const unsigned char *a = RCAST(const unsigned char *, s1);
const unsigned char *b = RCAST(const unsigned char *, s2);
- const unsigned char *eb = b + len;
+ uint32_t ws = flags & (STRING_COMPACT_WHITESPACE |
+ STRING_COMPACT_OPTIONAL_WHITESPACE);
+ const unsigned char *eb = b + (ws ? maxlen : len);
uint64_t v;
/*
@@ -1921,7 +1983,8 @@ file_strncmp(const char *s1, const char
}
private uint64_t
-file_strncmp16(const char *a, const char *b, size_t len, uint32_t flags)
+file_strncmp16(const char *a, const char *b, size_t len, size_t maxlen,
+ uint32_t flags)
{
/*
* XXX - The 16-bit string compare probably needs to be done
@@ -1929,7 +1992,7 @@ file_strncmp16(const char *a, const char
* At the moment, I am unsure.
*/
flags = 0;
- return file_strncmp(a, b, len, flags);
+ return file_strncmp(a, b, len, maxlen, flags);
}
private int
@@ -1980,6 +2043,7 @@ magiccheck(struct magic_set *ms, struct
case FILE_QWDATE:
case FILE_BEQWDATE:
case FILE_LEQWDATE:
+ case FILE_OFFSET:
v = p->q;
break;
@@ -2058,14 +2122,14 @@ magiccheck(struct magic_set *ms, struct
case FILE_PSTRING:
l = 0;
v = file_strncmp(m->value.s, p->s, CAST(size_t, m->vallen),
- m->str_flags);
+ sizeof(p->s), m->str_flags);
break;
case FILE_BESTRING16:
case FILE_LESTRING16:
l = 0;
v = file_strncmp16(m->value.s, p->s, CAST(size_t, m->vallen),
- m->str_flags);
+ sizeof(p->s), m->str_flags);
break;
case FILE_SEARCH: { /* search ms->search.s for the string m->value.s */
@@ -2100,7 +2164,7 @@ magiccheck(struct magic_set *ms, struct
return 0;
v = file_strncmp(m->value.s, ms->search.s + idx, slen,
- m->str_flags);
+ ms->search.s_len - idx, m->str_flags);
if (v == 0) { /* found match */
ms->search.offset += idx;
ms->search.rm_len = ms->search.s_len - idx;
@@ -2185,6 +2249,10 @@ magiccheck(struct magic_set *ms, struct
return 0;
}
return matched;
+ case FILE_GUID:
+ l = 0;
+ v = memcmp(m->value.guid, p->guid, sizeof(p->guid));
+ break;
default:
file_magerror(ms, "invalid type %d in magiccheck()", m->type);
return -1;
Index: src/external/bsd/file/include/config.h
diff -u src/external/bsd/file/include/config.h:1.15 src/external/bsd/file/include/config.h:1.16
--- src/external/bsd/file/include/config.h:1.15 Mon Dec 16 21:31:06 2019
+++ src/external/bsd/file/include/config.h Sun Jun 14 20:37:25 2020
@@ -277,7 +277,7 @@
#define PACKAGE_NAME "file"
/* Define to the full name and version of this package. */
-#define PACKAGE_STRING "file 5.38"
+#define PACKAGE_STRING "file 5.39"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "file"
@@ -286,7 +286,7 @@
#define PACKAGE_URL ""
/* Define to the version of this package. */
-#define PACKAGE_VERSION "5.38"
+#define PACKAGE_VERSION "5.39"
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
@@ -317,7 +317,7 @@
/* Version number of package */
-#define VERSION "5.38"
+#define VERSION "5.39"
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel). */
Index: src/external/bsd/file/lib/shlib_version
diff -u src/external/bsd/file/lib/shlib_version:1.7 src/external/bsd/file/lib/shlib_version:1.8
--- src/external/bsd/file/lib/shlib_version:1.7 Sun Apr 15 15:45:32 2018
+++ src/external/bsd/file/lib/shlib_version Sun Jun 14 20:37:25 2020
@@ -1,4 +1,4 @@
-# $NetBSD: shlib_version,v 1.7 2018/04/15 19:45:32 christos Exp $
+# $NetBSD: shlib_version,v 1.8 2020/06/15 00:37:25 christos Exp $
#
-major=6
+major=7
minor=0