Skip to content

Commit

Permalink
games/xnethack: fix behaviour with mismatched lua version
Browse files Browse the repository at this point in the history
The latest version of the package has introduced a "lua sandbox" that
comes with a version check against the bundled lua version.

As we unbundle lua, we cannot ensure that this version check succeeds.
Removal of the version check allows us to build a working binary, but
it is uncertain if there are any residual effects from the version
mismatch.

To rule out that possibility, the sandbox code is left disabled by
default but can be enabled if desired through the SANDBOX option.

PR:		264882
  • Loading branch information
clausecker authored and lwhsu committed Jun 25, 2022
1 parent 048b2cb commit 4f055da
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
9 changes: 8 additions & 1 deletion games/xnethack/Makefile
@@ -1,6 +1,7 @@
PORTNAME= xNetHack
DISTVERSIONPREFIX= xnh
DISTVERSION= 7.1
PORTREVISION= 1
CATEGORIES= games

MAINTAINER= fuz@fuz.su
Expand Down Expand Up @@ -49,7 +50,13 @@ GRAPHICS= QT_GRAPHICS

CFLAGS+= -DNOMAIL -DCURSES_GRAPHICS

OPTIONS_DEFINE= DOCS
# nhlua.c has a (patched out) version check for lua when the sandbox
# is used. As I cannot ascertain whether using the system's different
# lua version could cause problems, I'll leave the sandbox disabled by
# default.
OPTIONS_DEFINE= DOCS SANDBOX
SANDBOX_DESC= Run lua in a sandbox (untested)
SANDBOX_CFLAGS= -DNHL_SANDBOX

.include <bsd.port.pre.mk>

Expand Down
9 changes: 9 additions & 0 deletions games/xnethack/files/patch-include-config.h
Expand Up @@ -34,3 +34,12 @@
/* DUMPLOG_FILE allows following placeholders:
%% literal '%'
%v version (eg. "3.6.3-0")
@@ -697,7 +697,7 @@ typedef unsigned char uchar;
/* TEMPORARY - MAKE UNCONDITIONAL BEFORE RELEASE */
/* undef this to check if sandbox breaks something */
-#define NHL_SANDBOX
+/* #define NHL_SANDBOX */

/* End of Section 4 */

40 changes: 40 additions & 0 deletions games/xnethack/files/patch-src_nhlua.c
@@ -0,0 +1,40 @@
As we unbundle lua, we cannot ensure that this version check succeeds.
Removal of the version check allows us to build a working binary, but
it is uncertain if there are any residual effects from the version
mismatch.

To rule out that possibility, the sandbox code is left disabled by
default but can be enabled if desired through the SANDBOX option.

--- src/nhlua.c.orig 2022-06-25 04:31:43 UTC
+++ src/nhlua.c
@@ -1652,20 +1652,6 @@ DISABLE_WARNING_CONDEXPR_IS_CONSTANT
lua_State *
nhl_init(nhl_sandbox_info *sbi)
{
- /* It would be nice to import EXPECTED from each build system. XXX */
- /* And it would be nice to do it only once, but it's cheap. */
-#ifndef NHL_VERSION_EXPECTED
-#define NHL_VERSION_EXPECTED 50404
-#endif
-
-#ifdef NHL_SANDBOX
- if(NHL_VERSION_EXPECTED != LUA_VERSION_RELEASE_NUM){
- panic(
- "sandbox doesn't know this Lua version: this=%d != expected=%d ",
- LUA_VERSION_RELEASE_NUM, NHL_VERSION_EXPECTED);
- }
-#endif
-
lua_State *L = nhlL_newstate(sbi);

iflags.in_lua = TRUE;
@@ -2348,7 +2334,7 @@ nhlL_newstate (nhl_sandbox_info *sbi) {
}

lua_State *L = lua_newstate(nhl_alloc, nud);
-#if LUA_VERSION_NUM == 503
+#ifndef luai_likely
# define luai_likely(x) (x)
#endif
if (luai_likely(L)) {

0 comments on commit 4f055da

Please sign in to comment.