diff options
author | Karl Berry <karl@freefriends.org> | 2024-02-29 18:02:29 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2024-02-29 18:02:29 +0000 |
commit | 262eaacb2e4c3664ff7cc843e7498a5cb0f4d208 (patch) | |
tree | 01f0fa5e3f78acc30499cf5ba939a9be65e8256f /Build/source/texk/kpathsea | |
parent | 1462b330d97569e52c1e95aa93580108f76b2c67 (diff) |
consider exactly $TEXMF[SYS]VAR safe (to allow mkdir from lua)
git-svn-id: svn://tug.org/texlive/trunk@70253 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/kpathsea')
-rw-r--r-- | Build/source/texk/kpathsea/ChangeLog | 6 | ||||
-rwxr-xr-x | Build/source/texk/kpathsea/tests/kpsesafe.test | 35 | ||||
-rw-r--r-- | Build/source/texk/kpathsea/tex-file.c | 20 |
3 files changed, 49 insertions, 12 deletions
diff --git a/Build/source/texk/kpathsea/ChangeLog b/Build/source/texk/kpathsea/ChangeLog index 3bdb457c7bf..76ee9f02058 100644 --- a/Build/source/texk/kpathsea/ChangeLog +++ b/Build/source/texk/kpathsea/ChangeLog @@ -1,3 +1,9 @@ +2024-02-29 Karl Berry <karl@freefriends.org> + + * tex-file.c (abs_fname_ok): if extended, allow a dir that is the + exact match of TEXMF[SYS]VAR, since luatex might want to mkdir it. + * tests/kpsesafe.test: test it, both positive and negative. + 2024-02-23 Karl Berry <karl@freefriends.org> * texmf.cnf (XE_FONTCONFIG_PATH, XE_FC_CACHEDIR): rename from diff --git a/Build/source/texk/kpathsea/tests/kpsesafe.test b/Build/source/texk/kpathsea/tests/kpsesafe.test index 99b85c15b14..7739e7818b2 100755 --- a/Build/source/texk/kpathsea/tests/kpsesafe.test +++ b/Build/source/texk/kpathsea/tests/kpsesafe.test @@ -31,7 +31,7 @@ TEXMF_OUTPUT_DIRECTORY=/xdir \ TEXMFOUTPUT=/ydir \ $_kpsewhich --safe-out-name=/ydir/ofoo.tex || exit 10 -echo "TEXMF[SYS]VAR ok for writing only if extended." +echo "TEXMF[SYS]VAR not ok for writing unless extended." TEXMFVAR=/xvar \ $_kpsewhich --safe-out-name=/xvar/ofoo.tex && exit 11 TEXMFSYSVAR=/yvar \ @@ -41,17 +41,40 @@ TEXMFVAR=/avar \ $_kpsewhich --safe-extended-out-name=/avar/ofoo.tex || exit 13 TEXMFSYSVAR=/bvar \ $_kpsewhich --safe-extended-out-name=/bvar/ofoo.tex || exit 14 +# +# exact match should not be ok if not extended. +TEXMFVAR=/xvar \ + $_kpsewhich --safe-out-name=/xvar && exit 15 +TEXMFSYSVAR=/yvar \ + $_kpsewhich --safe-out-name=/yvar && exit 16 # In practice, TEXMFVAR=~/.texliveYYYY, so this is the case that matters, # but in principle it should work for TEXMFSYSVAR too. -echo "TEXMF[SYS]VAR ok for writing when if set to ~/.something." +echo "TEXMF[SYS]VAR ok for writing when if set to ~/.whatever." +TEXMFVAR='~/.xvar' \ + $_kpsewhich --safe-extended-out-name='~/.xvar/ofoo.tex' || exit 17 +TEXMFSYSVAR='~/.yvar' \ + $_kpsewhich --safe-extended-out-name='~/.yvar/ofoo.tex' || exit 18 + +echo "TEXMF[SYS]VAR exact string ok for writing if extended." TEXMFVAR='~/.xvar' \ - $_kpsewhich --safe-extended-out-name='~/.xvar/ofoo.tex' || exit 15 + $_kpsewhich --safe-extended-out-name='~/.xvar' || exit 21 TEXMFSYSVAR='~/.yvar' \ - $_kpsewhich --safe-extended-out-name='~/.yvar/ofoo.tex' || exit 16 + $_kpsewhich --safe-extended-out-name='~/.yvar' || exit 22 + +echo "TEXMF[SYS]VAR inexact string not ok for writing, even if extended." +TEXMFVAR='~/.xvar' \ + $_kpsewhich --safe-extended-out-name='~/.xvarx' && exit 23 +TEXMFSYSVAR='~/.yvar' \ + $_kpsewhich --safe-extended-out-name='~/.yvarx' && exit 24 +# +TEXMFVAR='~/.xvarx' \ + $_kpsewhich --safe-extended-out-name='~/.xvar' && exit 25 +TEXMFSYSVAR='~/.yvarx' \ + $_kpsewhich --safe-extended-out-name='~/.yvar' && exit 26 -echo "~/.ssh not ok for writing if TEXMF[SYS]VAR is set ~/.foo." +echo "~/.ssh not ok for writing if TEXMF[SYS]VAR is set to ~/.foo." TEXMFVAR='~/.foo' \ - $_kpsewhich --safe-extended-out-name='~/.ssh/ofoo.tex' && exit 17 + $_kpsewhich --safe-extended-out-name='~/.ssh/ofoo.tex' && exit 31 : # exit successfully if get to the end. diff --git a/Build/source/texk/kpathsea/tex-file.c b/Build/source/texk/kpathsea/tex-file.c index 29bab50d7d8..a748920d250 100644 --- a/Build/source/texk/kpathsea/tex-file.c +++ b/Build/source/texk/kpathsea/tex-file.c @@ -1186,12 +1186,18 @@ static const_string ok_type_name[] = { /* Helper subroutine to check if absolute pathname FNAME is acceptable in CHECKDIR. An absolute pathname is ok only if - CHECKDIR is set, - CHECKDIR is non-empty, + CHECKDIR is set, and + CHECKDIR is non-empty, and CHECKDIR is the beginning of FNAME (e.g., disallow /somedir/file.tex against /anotherdir), and - the next character in FNAME is a directory separator - (e.g., disallow /somedirx/file.tex against /somedir). */ + either the next character in FNAME is a directory separator + (e.g., disallow /somedirx/file.tex against /somedir). + or we're at the end of CHECKDIR + (e.g., allow /somedir against /somedir, without requiring /somedir/). + + This last case, of allowing FNAME == CHECKDIR, comes up with LuaTeX, + where we might want to lfs.mkdir(TEXMFVAR) within Lua, not + necessarily with a trailing /, although that suffices. */ static boolean abs_fname_ok (const_string fname, const_string checkdir) @@ -1199,8 +1205,10 @@ abs_fname_ok (const_string fname, const_string checkdir) return checkdir /* checkdir must be non-null */ && *checkdir != '\0' /* checkdir must be non-empty */ - && fname == strstr (fname, checkdir) /* fname must begin checkdir */ - && IS_DIR_SEP (fname[strlen (checkdir)]); /* and be followed by / */ + && fname == strstr (fname, checkdir) /* fname must begin checkdir */ + && (IS_DIR_SEP (fname[strlen (checkdir)]) /* and be followed by / */ + || strlen (fname) == strlen (checkdir) /* or be the whole string */ + ); } /* Here is the general internal subroutine, kpathsea_name_ok, for |