Skip to content

Commit

Permalink
LuaTeX 1.17.0 .
Browse files Browse the repository at this point in the history
git-svn-id: svn://tug.org/texlive/trunk/Build/source@66967 c570f23f-e606-0410-a88d-b1316a301751
  • Loading branch information
luigiScarso committed Apr 29, 2023
1 parent 7a91b32 commit 6ace460
Show file tree
Hide file tree
Showing 15 changed files with 932 additions and 636 deletions.
31 changes: 31 additions & 0 deletions texk/web2c/luatexdir/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
2023-04-29 Luigi Scarso <luigi.scarso@gmail.com>
* LuaTeX 1.17.0

2023-04-28 Luigi Scarso <luigi.scarso@gmail.com>
* new option --no-socket, same as --nosocket

2023-04-27 Luigi Scarso <luigi.scarso@gmail.com>
* new option --socket to split socket and shell escape;
* the mime library is always available (Max Chernoff);
* Fixed ChangeLog

2023-04-25 Luigi Scarso <luigi.scarso@gmail.com>
* socket library by default not enabled;
it is enabled with --shell-escape but not with --shell-restricted.
The option ---nosocket remains unchanged.
The two new functions os.socketgettime and os.socketsleep are
like socket.gettime and socket.sleep, but they are always available.
* Luatex 1.17.0

2023-04-24 Luigi Scarso <luigi.scarso@gmail.com>
* static kpse.check_permissions in os.kpsepopen
* Fixed date in ChangeLog

2023-04-23 Luigi Scarso <luigi.scarso@gmail.com>
* new os.kpsepopen -- replace io.popen if kpse is active.
* Luatex 1.16.2

2023-04-18 Luigi Scarso <luigi.scarso@gmail.com>
* lua.setluaname(n, s) and lua.getluaname(n):
fixed mismatch between documentation and implementation (J. Friedrich).

2023-03-30 Luigi Scarso <luigi.scarso@gmail.com>
* bugfix for setpdforigin() (A. Matthias)

Expand Down
24 changes: 24 additions & 0 deletions texk/web2c/luatexdir/NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
==============================================================
LuaTeX 1.17.0 2023-04-29
==============================================================

- A breaking backward compatibility change: by default the socket
library is not enabled .
The new option --socket enable the socket library as
before, as also --shell-escape (without --shell-restricted);
--nosocket, --no-socket , --safer disabled the library, and
they have the priority in case of conflicting options.
The mime library is always available; socket.sleep
and socket.gettime are duplicated as os.socketsleep
and os.socketgettime, both always available.
The new os.kpsepopen replace io.popopen in kpse mode
(i.e. when kpse_init is not zero) as it was before
but the permission now cannot be changed anymore with
kpse.check_permission .
The function os.kpsepopen follows the same restrictions
as io.popen .
Thanks to Max Chernoff for debugging.




==============================================================
LuaTeX 1.16.0 2023-02-19
==============================================================
Expand Down
3 changes: 1 addition & 2 deletions texk/web2c/luatexdir/font/writettf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ static void do_writeotf(PDF pdf, fd_entry * fd)
if (tracefilenames)
tex_printf("<<%s", cur_file_name);
ttf_read_tabdir();
/*tex Read teh font parameters. */
/*tex Read the font parameters. */
if (ttf_name_lookup("head", false) != NULL)
ttf_read_head();
if (ttf_name_lookup("hhea", false) != NULL)
Expand Down Expand Up @@ -1570,4 +1570,3 @@ void writeotf(PDF pdf, fd_entry * fd)
xfree(ttf_buffer);
cur_file_name = NULL;
}

10 changes: 5 additions & 5 deletions texk/web2c/luatexdir/lua/llualib.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,17 @@ static int set_luaname(lua_State * L)
{
int k;
const char *s;
if (lua_gettop(L) == 3) {
k = (int) luaL_checkinteger(L, 2);
if (lua_gettop(L) == 2) {
k = (int) luaL_checkinteger(L, 1);
if (k > 65535 || k < 0) {
/* error */
} else {
if (luanames[k] != NULL) {
free(luanames[k]);
luanames[k] = NULL;
}
if (lua_type(L,3) == LUA_TSTRING) {
s = lua_tostring(L, 3);
if (lua_type(L, 2) == LUA_TSTRING) {
s = lua_tostring(L, 2);
if (s != NULL)
luanames[k] = xstrdup(s);
}
Expand All @@ -340,7 +340,7 @@ static int set_luaname(lua_State * L)

static int get_luaname(lua_State * L)
{
int k = (int) luaL_checkinteger(L, 2);
int k = (int) luaL_checkinteger(L, 1);
if (k > 65535 || k < 0) {
/* error */
lua_pushnil(L);
Expand Down
171 changes: 171 additions & 0 deletions texk/web2c/luatexdir/lua/loslibext.c
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,167 @@ static int os_execute(lua_State * L)
}


/*
** ======================================================
** l_kpse_popen spawns a new process connected to the current
** one through the file streams with some checks by kpse.
** Almost verbatim from Lua liolib.c .
** =======================================================
*/
#if !defined(l_kpse_popen) /* { */

#if defined(LUA_USE_POSIX) /* { */

#define l_kpse_popen(L,c,m) (fflush(NULL), popen(c,m))
#define l_kpse_pclose(L,file) (pclose(file))

#elif defined(LUA_USE_WINDOWS) /* }{ */

#define l_kpse_popen(L,c,m) (_popen(c,m))
#define l_kpse_pclose(L,file) (_pclose(file))

#else /* }{ */

/* ISO C definitions */
#define l_kpse_popen(L,c,m) \
((void)((void)c, m), \
luaL_error(L, "'popen' not supported"), \
(FILE*)0)
#define l_kpse_pclose(L,file) ((void)L, (void)file, -1)

#endif /* } */

#endif /* } */
typedef luaL_Stream LStream;
#define tolstream(L) ((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))
static LStream *newprefile (lua_State *L) {
LStream *p = (LStream *)lua_newuserdata(L, sizeof(LStream));
p->closef = NULL; /* mark file handle as 'closed' */
luaL_setmetatable(L, LUA_FILEHANDLE);
return p;
}
static int io_kpse_pclose (lua_State *L) {
LStream *p = tolstream(L);
return luaL_execresult(L, l_kpse_pclose(L, p->f));
}
static int io_kpse_check_permissions(lua_State *L) {
const char *filename = luaL_checkstring(L, 1);
if (filename == NULL) {
lua_pushboolean(L,0);
lua_pushliteral(L,"no command name given");
} else if (shellenabledp <= 0) {
lua_pushboolean(L,0);
lua_pushliteral(L,"all command execution is disabled");
} else if (restrictedshell == 0) {
lua_pushboolean(L,1);
lua_pushstring(L,filename);
} else {
char *safecmd = NULL;
char *cmdname = NULL;
switch (shell_cmd_is_allowed(filename, &safecmd, &cmdname)) {
case 0:
lua_pushboolean(L,0);
lua_pushliteral(L, "specific command execution disabled");
break;
case 1:
/* doesn't happen */
lua_pushboolean(L,1);
lua_pushstring(L,filename);
break;
case 2:
lua_pushboolean(L,1);
lua_pushstring(L,safecmd);
break;
default:
/* -1 */
lua_pushboolean(L,0);
lua_pushliteral(L, "bad command line quoting");
break;
}
}
return 2;
}
static int io_kpse_popen (lua_State *L) {
const char *filename = NULL;
const char *mode = NULL;
LStream *p = NULL;
int okay;
filename = luaL_checkstring(L, 1);
mode = luaL_optstring(L, 2, "r");
lua_pushstring(L,filename);
io_kpse_check_permissions(L);
filename = luaL_checkstring(L, -1);
okay = lua_toboolean(L,-2);
if (okay && filename) {
p = newprefile(L);
luaL_argcheck(L, ((mode[0] == 'r' || mode[0] == 'w') && mode[1] == '\0'),
2, "invalid mode");
p->f = l_kpse_popen(L, filename, mode);
p->closef = &io_kpse_pclose;
return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
} else {
lua_pushnil(L);
lua_pushvalue(L,-2);
return 2;
}
}



/* socket.sleep and socket.gettime */
/* are duplicated here, and they are */
/* always available (the socket library */
/* can be nil in some setups) */
#ifdef _WIN32
static int socket_timeout_lua_sleep(lua_State *L)
{
double n = luaL_checknumber(L, 1);
if (n < 0.0) n = 0.0;
if (n < DBL_MAX/1000.0) n *= 1000.0;
if (n > INT_MAX) n = INT_MAX;
Sleep((int)n);
return 0;
}
static double socket_timeout_gettime(void) {
FILETIME ft;
double t;
GetSystemTimeAsFileTime(&ft);
/* Windows file time (time since January 1, 1601 (UTC)) */
t = ft.dwLowDateTime/1.0e7 + ft.dwHighDateTime*(4294967296.0/1.0e7);
/* convert to Unix Epoch time (time since January 1, 1970 (UTC)) */
return (t - 11644473600.0);
}
#else
static int socket_timeout_lua_sleep(lua_State *L)
{
double n = luaL_checknumber(L, 1);
struct timespec t, r;
if (n < 0.0) n = 0.0;
if (n > INT_MAX) n = INT_MAX;
t.tv_sec = (int) n;
n -= t.tv_sec;
t.tv_nsec = (int) (n * 1000000000);
if (t.tv_nsec >= 1000000000) t.tv_nsec = 999999999;
while (nanosleep(&t, &r) != 0) {
t.tv_sec = r.tv_sec;
t.tv_nsec = r.tv_nsec;
}
return 0;
}
static double socket_timeout_gettime(void) {
struct timeval v;
gettimeofday(&v, (struct timezone *) NULL);
/* Unix Epoch time (time since January 1, 1970 (UTC)) */
return v.tv_sec + v.tv_usec/1.0e6;
}
#endif
static int socket_timeout_lua_gettime(lua_State *L)
{
lua_pushnumber(L, socket_timeout_gettime());
return 1;
}


void open_oslibext(lua_State * L)
{

Expand Down Expand Up @@ -1081,5 +1242,15 @@ void open_oslibext(lua_State * L)
lua_pushcfunction(L, os_tmpdir);
lua_setfield(L, -2, "tmpdir");

lua_pushcfunction(L, io_kpse_popen);
lua_setfield(L, -2, "kpsepopen");

lua_pushcfunction(L, socket_timeout_lua_sleep);
lua_setfield(L, -2, "socketsleep");

lua_pushcfunction(L, socket_timeout_lua_gettime);
lua_setfield(L, -2, "socketgettime");


lua_pop(L, 1); /* pop the table */
}
39 changes: 32 additions & 7 deletions texk/web2c/luatexdir/lua/luainit.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ const_string LUATEX_IHELP[] = {
" --lua=FILE load and execute a lua initialization script",
" --[no-]mktex=FMT disable/enable mktexFMT generation (FMT=tex/tfm)",
" --nosocket disable the lua socket library",
" --no-socket disable the lua socket library",
" --socket enable the lua socket library",
" --output-comment=STRING use STRING for DVI file comment instead of date (no effect for PDF)",
" --output-directory=DIR use existing DIR as the directory to write files in",
" --output-format=FORMAT use FORMAT for job output; FORMAT is 'dvi' or 'pdf'",
Expand All @@ -108,6 +110,7 @@ const_string LUATEX_IHELP[] = {
#endif
"",
"See the reference manual for more information about the startup process.",
"LuaTeX package page: https://ctan.org/pkg/luatex",
NULL
};

Expand Down Expand Up @@ -212,9 +215,30 @@ char *jithash_hashname = NULL;
#endif

int safer_option = 0;
int nosocket_option = 0;
int nosocket_option = 1;
int nosocket_cli_option = 0;
int yessocket_cli_option = 0;
int socket_bitmask = 0;
int utc_option = 0;

/*tex We use a bitmask for the socket library: |0000| and |1xxx| implies |--nosocket|,
otherwise the socket library is enabled. Default value is |0000|, i.e. |--nosocket|.
*/
#define UPDATE_SOCKET_STATUS() do { \
socket_bitmask = 0; \
socket_bitmask = safer_option==1? (8+socket_bitmask):socket_bitmask;\
socket_bitmask = nosocket_cli_option==1? (4+socket_bitmask):socket_bitmask;\
socket_bitmask = (shellenabledp == 1 && restrictedshell == 0)?(2+socket_bitmask):socket_bitmask;\
socket_bitmask = yessocket_cli_option==1? (1+socket_bitmask):socket_bitmask;\
if( socket_bitmask==0) { \
nosocket_option = 1; \
} else if ( socket_bitmask<4) { \
nosocket_option = 0; \
} else { \
nosocket_option = 1; \
} \
} while (0)

/*tex
Test whether getopt found an option ``A''. Assumes the option index is in the
Expand Down Expand Up @@ -242,7 +266,9 @@ static struct option long_options[] = {
#endif
{"safer", 0, &safer_option, 1},
{"utc", 0, &utc_option, 1},
{"nosocket", 0, &nosocket_option, 1},
{"nosocket", 0, &nosocket_cli_option, 1},
{"no-socket", 0, &nosocket_cli_option, 1},
{"socket", 0, &yessocket_cli_option, 1},
{"help", 0, 0, 0},
{"ini", 0, &ini_version, 1},
{"interaction", 1, 0, 0},
Expand Down Expand Up @@ -524,14 +550,11 @@ static void parse_options(int ac, char **av)
input_name = xstrdup(sargv[sargc-1]);
sargv[sargc-1] = normalize_quotes(input_name, "argument");
}
if (safer_option) /* --safer implies --nosocket */
nosocket_option = 1;
UPDATE_SOCKET_STATUS();
return;
#endif
}
/*tex |--safer| implies |--nosocket| */
if (safer_option)
nosocket_option = 1;
UPDATE_SOCKET_STATUS();
/*tex Finalize the input filename. */
if (input_name != NULL) {
argv[optind] = normalize_quotes(input_name, "argument");
Expand Down Expand Up @@ -981,6 +1004,7 @@ void lua_initialize(int ac, char **av)
shellenabledp = true;
restrictedshell = false;
safer_option = 0;
nosocket_option = 0;
}
/*tex
Get the current locale (it should be |C|) and save |LC_CTYPE|, |LC_COLLATE|
Expand Down Expand Up @@ -1149,6 +1173,7 @@ void lua_initialize(int ac, char **av)
}
free(v1);
}
UPDATE_SOCKET_STATUS();
/*tex If shell escapes are restricted, get allowed cmds from cnf. */
if (shellenabledp && restrictedshell == 1) {
v1 = NULL;
Expand Down
Loading

0 comments on commit 6ace460

Please sign in to comment.