From 78f4edd4de022f7285d3fcc859e00e03d1058f1d Mon Sep 17 00:00:00 2001
From: Luigi Scarso <luigi.scarso@gmail.com>
Date: Wed, 28 Mar 2018 08:01:58 +0000
Subject: [PATCH] (trunk) Sync with TeX Live revision 47145.

---
 source/README                                 | 28 ++++------
 source/doc/README.solaris                     | 12 ++---
 source/texk/README                            |  8 +--
 source/texk/kpathsea/texmf.cnf                |  2 +-
 source/texk/texlive/w32_wrapper/runscript.tlu | 51 +++++++++++++++++--
 .../texk/web2c/luatexdir/luatex_svnversion.h  |  2 +-
 6 files changed, 70 insertions(+), 33 deletions(-)

diff --git a/source/README b/source/README
index 9c904e5ca..a747c01ed 100644
--- a/source/README
+++ b/source/README
@@ -1,4 +1,4 @@
-$Id: README 46966 2018-03-14 23:01:23Z karl $
+$Id: README 47075 2018-03-22 16:17:51Z mojca $
 Public domain.  Originally written 2005 by Karl Berry.
 
 For a high-level overview of building TeX Live, see
@@ -31,23 +31,25 @@ aarch64-linux:
   gcc (Debian 6.3.0-18) 6.3.0 20170516
   ./Build --enable-arm-neon=check
 
-amd64-netbsd:
+i386-netbsd, amd64-netbsd:
   gcc version 4.5.3 (NetBSD nb2 20110806)
   NetBSD/amd64 6.1.3
   TL_MAKE=gmake CC=gcc CXX=g++ CFLAGS=-D_NETBSD_SOURCE \
   LDFLAGS='-L/usr/X11R7/lib -Wl,-rpath,/usr/X11R7/lib' \
   ./Build --enable-xindy CLISP=/usr/local/bin/clisp
-  
+
 i386-freebsd, amd64-freebsd:
   --disable-dvisvgm; upmendex for i386 built with -DU_IS_BIG_ENDIAN=0.
 
-i386-linux: Debian 7.
+i386-linux, x86_64-linux:
+  Debian 8.0 (Jessie), Apr 2015.
 
 i386-openbsd, amd64-openbsd:
   e.g., see CONFIGURE_ARGS in the Makefile in
   http://cvsweb.openbsd.org/cgi-bin/cvsweb/ports/print/texlive/base/
 
-i386-solaris, x86_64-solaris: Solaris 10.  See doc/README.solaris.
+i386-solaris, x86_64-solaris, sparc-solaris:
+  Solaris 10, gcc 5.5.  See doc/README.solaris.
 
 i386-cygwin, x86_64-cygwin: gcc-4.8.2, cygwin-1.7.29.
   ./Build (with --enable-xindy for i386).
@@ -57,25 +59,15 @@ powerpc-linux (Debian Squeeze):
   ppc64 Debian GNU/Linux 6.0
   (only the kernel is 64bit, the entire userland is 32bit)
 
-sparc-solaris: Solaris 10, gcc.  See doc/README.solaris.
-
 x86_64-darwin:
+  OS X 10.10
   See Master/source/mactexdoc.tar.xz.
 
-x86_64-darwinlegacy, i386-darwin, powerpc-darwin:
+x86_64-darwinlegacy:
+  Mac OS X 10.6, clang 5.0, libc++ required
   https://github.com/TeXLive-M/texlive-buildbot
   http://build.contextgarden.net/waterfall?tag=c/texlive
   (These links have info on all platforms built by Mojca.)
-  
-  32-bit binaries built on 10.6/x86_64 with backward compatibility to 10.5.
-  ppc binaries only work on <= 10.5, so 10.5/ppc will be the only OS for them.
-  i386 binaries only work on <= 10.6. While they theoretically work
-    "everywhere", they would only be used on 10.5 and 10.6/i386.
-  x86_64 binaries only work on >= 10.6 (and should work on any >= 10.6 machine)
-    but will only be used for < 10.10 since x86_64-darwin covers newer.
-  PPC binaries made with gcc-4.2 and Intel binaries with clang-3.7.
-
-x86_64-linux: Debian 8.0 (Jessie), Apr 2015.
 
 x86_64-linuxmusl:
   Alpine 3.1 Docker image with musl libc 1.1.5
diff --git a/source/doc/README.solaris b/source/doc/README.solaris
index 45f10cad8..fe7aed845 100644
--- a/source/doc/README.solaris
+++ b/source/doc/README.solaris
@@ -41,10 +41,10 @@ You can check the libc version with
 Building for 64-bit
 ===================
 
-All binaries have been compiled with gcc-5.2.
+All binaries have been compiled with gcc-5.5.
 The only thing that is needed to build for 64-bit is to define
-    export CC="/path/to/gcc-5.2 -m64"
-    export CXX="/path/to/g++-5.2 -m64"
+    export CC="/path/to/gcc-5.5 -m64"
+    export CXX="/path/to/g++-5.5 -m64"
 
 Building wget
 =============
@@ -121,8 +121,8 @@ Building asymptote
 
 Asymptote has been built with the following flags:
 
-export CC=/opt/csw/bin/gcc-5.2
-export CXX=/opt/csw/bin/g++-5.2
+export CC=/opt/csw/bin/gcc-5.5
+export CXX=/opt/csw/bin/g++-5.5
 ./configure --prefix=/tmp/asyinst --enable-texlive-build \
     --disable-fftw --disable-offscreen --disable-sigsegv \
     --disable-gl --disable-gsl --disable-readline
@@ -170,7 +170,7 @@ The resulting binary depends on:
 Building texlive
 ================
 
-Additional settings were needed to compile TeX Live with gcc 5.2:
+Additional settings were needed to compile TeX Live with gcc 5.5:
   * ./Build --without-iconv
 
 The '--without-iconv' makes sure to avoid linking against libiconv
diff --git a/source/texk/README b/source/texk/README
index 8dce7398b..50c697a8e 100644
--- a/source/texk/README
+++ b/source/texk/README
@@ -1,4 +1,4 @@
-$Id: README 46939 2018-03-12 23:07:15Z kakuto $
+$Id: README 47119 2018-03-25 22:51:55Z kakuto $
 Copyright 2006-2018 TeX Users Group.
 You may freely use, modify and/or distribute this file.
 
@@ -59,11 +59,11 @@ dvipos - maintained here, by us
 
 dvipsk - maintained here, by us
 
-dvisvgm 2.3.3 - checked 21feb18
+dvisvgm 2.3.5 - checked 24mar18
   http://dvisvgm.bplaced.net/Downloads
 
-gregorio 5.1.0 - checked 12mar18
-  CTAN/support/gregoriotex/gregorio-5.1.0.zip
+gregorio 5.1.1 - checked 25mar18
+  CTAN/support/gregoriotex/gregorio-5.1.1.zip
 
 gsftopk - from Paul Vojta's xdvi?
 
diff --git a/source/texk/kpathsea/texmf.cnf b/source/texk/kpathsea/texmf.cnf
index 83cbc5d3f..7d5acb45a 100644
--- a/source/texk/kpathsea/texmf.cnf
+++ b/source/texk/kpathsea/texmf.cnf
@@ -819,5 +819,5 @@ max_rows.gftype = 8191
 max_cols.gftype = 8191
 
 % Guess input encoding (SJIS vs. Unicode, etc.) in pTeX and friends?
-% Default is 0, to not guess.
+% Default is 1, to guess. Used on Windows only.
 guess_input_kanji_encoding = 1
diff --git a/source/texk/texlive/w32_wrapper/runscript.tlu b/source/texk/texlive/w32_wrapper/runscript.tlu
index 983e00818..77873abd3 100644
--- a/source/texk/texlive/w32_wrapper/runscript.tlu
+++ b/source/texk/texlive/w32_wrapper/runscript.tlu
@@ -1,7 +1,7 @@
 
 
-local svnrevision = string.match("$Revision: 46914 $", "%d+") or "0"
-local svndate     = string.match("$Date: 2018-03-10 04:48:22 +0100 (Sat, 10 Mar 2018) $", "[-%d]+") or "2009-12-04"
+local svnrevision = string.match("$Revision: 46945 $", "%d+") or "0"
+local svndate     = string.match("$Date: 2018-03-13 14:42:02 +0900 (火, 13 3 2018) $", "[-%d]+") or "2009-12-04"
 local bannerstr   = "runscript wrapper utility (rev. " ..
                     svnrevision .. ", " .. svndate .. ")\n" .. 
                     "usage:   runscript script-name [arguments]\n" ..
@@ -262,6 +262,8 @@ local docstr = [[
     2017/05/06
         - introduce sys_user_progs, make checks for updmap/fmtutil
           use sys_user_progs instead, add kanji-config-updmap
+    2018/03/12
+        - introduce a new function gettexmfdist() for security.
 ]]
 
 -- HELPER SUBROUTINES --
@@ -386,6 +388,44 @@ local function mkdir_plus(dir)
   end
 end
 
+--
+-- return the TEXMFDIST directory in TeX Live
+--
+local function gettexmfdist()
+  local ffi = require("ffi")
+  ffi.cdef[[
+  typedef void*  HANDLE;
+  typedef char*  LPCSTR;
+  int GetModuleFileNameA(HANDLE h, LPCSTR l, int i);
+  HANDLE GetModuleHandleA(const char *a);
+  ]]
+  local buffer = ffi.new("char[?]", 512)
+  local runscripthandle = ffi.C.GetModuleHandleA("runscript.dll")
+  if runscripthandle == nil then
+    return nil
+  end
+  local err = ffi.C.GetModuleFileNameA(runscripthandle, buffer, 256)
+  if err == 0 then
+    return nil
+  end
+  local str = ffi.string(buffer)
+  str = string.gsub(str, "\\","/")
+  str = string.reverse(str)
+  local a, b
+-- remove /runscript.dll
+  a, b = string.find(str, '/', 1, true)
+  str = string.sub(str,a+1)
+-- remove /win32
+  a, b = string.find(str, '/', 1, true)
+  str = string.sub(str,a+1)
+-- remove /bin
+  a, b = string.find(str, '/', 1, true)
+  str = string.sub(str,a+1)
+  str = string.reverse(str)
+  str = str .. '/texmf-dist'
+  return str
+end
+
 -- MAIN_CHUNK -- encapsulated in a function for more robust execution with pcall
 
 local function MAIN_CHUNK()
@@ -472,7 +512,12 @@ kpse.set_program_name(lua_binary, progname)
 
 -- various dir-vars
 local TEXDIR = kpse.var_value('SELFAUTOPARENT')
-local TEXMFDIST = kpse.var_value('TEXMFDIST')
+-- local TEXMFDIST = kpse.var_value('TEXMFDIST')
+-- use a new function to obtain TEXMFDIST
+local TEXMFDIST = gettexmfdist()
+if TEXMFDIST == nil then
+  TEXMFDIST = kpse.var_value('TEXMFDIST')
+end
 local BINDIR = kpse.var_value('SELFAUTOLOC')
 local PATH = os.getenv('PATH') or ''
 
diff --git a/source/texk/web2c/luatexdir/luatex_svnversion.h b/source/texk/web2c/luatexdir/luatex_svnversion.h
index 151b8f063..c862e696a 100644
--- a/source/texk/web2c/luatexdir/luatex_svnversion.h
+++ b/source/texk/web2c/luatexdir/luatex_svnversion.h
@@ -1 +1 @@
-#define luatex_svn_revision 6678
+#define luatex_svn_revision 6680
-- 
GitLab