summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile23
-rw-r--r--src/supple_paths.h.in3
-rw-r--r--src/wrapper.c9
3 files changed, 31 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index c98517a..8f6533e 100644
--- a/Makefile
+++ b/Makefile
@@ -28,12 +28,26 @@ CMOD_OBJECTS := $(patsubst %,lib/%.o,$(subst .,/,$(CMODULES)))
LUA_INTERP_NAME := lua$(LUA_VER)
LUA_INTERP_PATH := $(shell which lua$(LUA_VER))
+# Override these variables
+# to bake LUA_PATH and LUA_CPATH environment variables into the sandbox binary.
+# They can't be set at runtime for security reasons.
+BAKE_SUPPLE_PATHS := 0
+SUPPLE_LUA_PATH := ""
+SUPPLE_LUA_CPATH := ""
+
+ifeq ($(BAKE_SUPPLE_PATHS), 1)
+ DEF_BAKE_SUPPLE_PATHS=-DBAKE_SUPPLE_PATHS
+else
+ DEF_BAKE_SUPPLE_PATHS=
+endif
+
INCS := -I/usr/include/lua$(LUA_VER)
OPT := -O0 -g
WARN := -Wall -Werror
DEFS := -D'LUA_INTERP_NAME="$(LUA_INTERP_NAME)"' \
-D'LUA_INTERP_PATH="$(LUA_INTERP_PATH)"' \
- -D'WRAPPER_PATH="$(WRAPPER_PATH)"'
+ -D'WRAPPER_PATH="$(WRAPPER_PATH)"' $(DEF_BAKE_SUPPLE_PATHS)
+
CFLAGS := $(INCS) $(OPT) $(WARN) $(DEFS) $(CFLAGS)
LFLAGS := -O1 -g $(LFLAGS)
@@ -45,7 +59,10 @@ LFLAGS := -O1 -g $(LFLAGS)
build: $(CMOD_TARGETS) wrapper
-wrapper: src/wrapper.c
+src/supple_paths.h: src/supple_paths.h.in
+ sed -e 's|@@SUPPLE_LUA_PATH@@|$(SUPPLE_LUA_PATH)|' -e 's|@@SUPPLE_LUA_CPATH@@|$(SUPPLE_LUA_CPATH)|' < $< > $@
+
+wrapper: src/wrapper.c src/supple_paths.h
$(CC) $(LFLAGS) $(CFLAGS) -o $@ $< $(LIB_LUA)
testwrapper: src/wrapper.c
@@ -80,7 +97,7 @@ LUA := SUPPLE_TEST_WRAPPER="$(shell pwd)/testwrapper" LUA_PATH="$(shell pwd)/lib
clean:
$(RM) luacov.report.out luacov.stats.out
$(RM) $(CMOD_TARGETS) $(CMOD_OBJECTS)
- $(RM) wrapper testwrapper
+ $(RM) wrapper testwrapper supple_paths.h
$(RM) -r html
distclean: clean
diff --git a/src/supple_paths.h.in b/src/supple_paths.h.in
new file mode 100644
index 0000000..7ed0b0b
--- /dev/null
+++ b/src/supple_paths.h.in
@@ -0,0 +1,3 @@
+
+#define SUPPLE_LUA_PATH "@@SUPPLE_LUA_PATH@@"
+#define SUPPLE_LUA_CPATH "@@SUPPLE_LUA_CPATH@@"
diff --git a/src/wrapper.c b/src/wrapper.c
index 9cc90cd..c7ed535 100644
--- a/src/wrapper.c
+++ b/src/wrapper.c
@@ -18,6 +18,8 @@
#include <stdlib.h>
#include <stdio.h>
+#include "supple_paths.h"
+
typedef struct {
int retcode;
} prot_args;
@@ -62,7 +64,12 @@ main(int argc, char **argv)
int success;
/* Perform pre-lua-interpreter initialisation */
-#ifndef TESTING_SUPPLE
+#if defined BAKE_SUPPLE_PATHS
+ setenv("LUA_PATH", SUPPLE_LUA_PATH, 1);
+ setenv("LUA_CPATH", SUPPLE_LUA_CPATH, 1);
+ unsetenv("SUPPLE_MKDTEMP");
+ unsetenv("LUA_INIT");
+#elif !defined TESTING_SUPPLE
unsetenv("LUA_PATH");
unsetenv("LUA_CPATH");
unsetenv("SUPPLE_MKDTEMP");