Skip to content

Commit 5c84b76

Browse files
committed
Switch from SpiderMonkey 1.7 to Duktape
pacparser currently vendors SpiderMonkey 1.7, a JavaScript engine that predates the Obama presidency. There's been a ton of changes to JavaScript and best practices when it comes to security and portability, so using this old version of SM doesn't make sense anymore. People are [trivially able to write exploits][ancientmonkey] against this old version, and seeing as PAC files could come from untrusted networks, that doesn't seem like a wise decision. To replace it, I've used duktape, a popular compact and embeddable JS runtime. There are a lot, but duktape seems popular; for example, polkit switched from (newer) SpiderMonkey to duktape. The only change I've needed to make to JS code is that RegExps don't seem to be callable under duktape; they aren't under V8 either though, so this might have been a Mozilla-ism. The massively smaller codebase of duktape is hopefully better security and maintainability wise, but also results in much smaller binaries. For example, pactester goes from 1.5M to 687K on my system. Passes unit tests on macOS. Not tested on Linux/Windows yet. However, I'm not certain about i.e. string lifetimes with duktape. They didn't seem clear with SpiderMonkey either though; perhaps it'd be an opportunity to i.e. explicitly strdup them? [ancientmonkey]: https://blog.pspaul.de/posts/ancient-monkey-pwning-a-17-year-old-version-of-spidermonkey/
1 parent c4ac28b commit 5c84b76

File tree

165 files changed

+105939
-119116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+105939
-119116
lines changed

src/Makefile

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ LIB_VER = 1
4545
SO_SUFFIX = so
4646
LIBRARY = $(LIBRARY_NAME).$(SO_SUFFIX).$(LIB_VER)
4747
MKSHLIB = $(CC) -shared
48-
LIB_OPTS = -Wl,-soname=$(LIBRARY) -Wl,-exclude-libs=libjs.a
48+
LIB_OPTS = -Wl,-soname=$(LIBRARY) -Wl,-exclude-libs=duktape.o
4949
SHFLAGS = -fPIC
5050
SMCFLAGS = -DHAVE_VA_COPY -DVA_COPY=va_copy
5151

@@ -78,9 +78,6 @@ ifndef PYTHON
7878
PYTHON = python
7979
endif
8080

81-
# Spidermonkey library.
82-
MAINT_CFLAGS += -Ispidermonkey/js/src
83-
8481
LIBRARY_LINK = $(LIBRARY_NAME).$(SO_SUFFIX)
8582
PREFIX := $(DESTDIR)$(PREFIX)
8683
LIB_PREFIX = $(PREFIX)/lib
@@ -92,23 +89,19 @@ MAN_PREFIX = $(PREFIX)/share/man
9289
.PHONY: clean pymod install-pymod
9390
all: testpactester
9491

95-
jsapi_buildstamp: spidermonkey/js/src
96-
cd spidermonkey && SMCFLAGS="$(SHFLAGS) $(SMCFLAGS)" $(MAKE) jsapi
97-
touch jsapi_buildstamp
98-
99-
spidermonkey/libjs.a: spidermonkey/js/src
100-
cd spidermonkey && SMCFLAGS="$(SHFLAGS) $(SMCFLAGS)" $(MAKE) jslib
92+
duktape.o: duktape.c duktape.h duk_config.h
93+
$(CC) $(MAINT_CFLAGS) $(CFLAGS) $(SHFLAGS) -c duktape.c -o dutape.o
94+
touch pymod/duktape_o_buildstamp
10195

102-
pacparser.o: pacparser.c pac_utils.h pacparser.h jsapi_buildstamp
96+
pacparser.o: pacparser.c pac_utils.h pacparser.h
10397
$(CC) $(MAINT_CFLAGS) $(CFLAGS) $(SHFLAGS) -c pacparser.c -o pacparser.o
10498
touch pymod/pacparser_o_buildstamp
10599

106-
$(LIBRARY): pacparser.o spidermonkey/libjs.a
107-
$(MKSHLIB) $(MAINT_CFLAGS) $(CFLAGS) $(LDFLAGS) $(LIB_OPTS) -o $(LIBRARY) pacparser.o spidermonkey/libjs.a -lm
100+
$(LIBRARY): pacparser.o duktape.o
101+
$(MKSHLIB) $(MAINT_CFLAGS) $(CFLAGS) $(LDFLAGS) $(LIB_OPTS) -o $(LIBRARY) pacparser.o duktape.o -lm
108102

109-
libpacparser.a: pacparser.o spidermonkey/libjs.a
110-
cp spidermonkey/libjs.a libpacparser.a
111-
ar rcs libpacparser.a pacparser.o
103+
libpacparser.a: pacparser.o duktape.o
104+
ar rcs libpacparser.a pacparser.o duktape.o
112105

113106
$(LIBRARY_LINK): $(LIBRARY)
114107
ln -sf $(LIBRARY) $(LIBRARY_LINK)
@@ -149,11 +142,11 @@ dist: all
149142
zip -r $${bindir}.zip $${bindir}/.
150143

151144
# Targets to build python module
152-
pymod: pacparser.o pacparser.h spidermonkey/libjs.a
145+
pymod: pacparser.o pacparser.h duktape.o
153146
cd pymod && ARCHFLAGS="" $(PYTHON) setup.py build
154147
$(PYTHON) ../tests/runtests.py
155148

156-
pymod-dist: pacparser.o pacparser.h spidermonkey/libjs.a
149+
pymod-dist: pacparser.o pacparser.h duktape.o
157150
cd pymod && ARCHFLAGS="" $(PYTHON) setup.py build
158151
cd pymod && ARCHFLAGS="" $(PYTHON) setup.py dist
159152
$(PYTHON) ../tests/runtests.py
@@ -165,4 +158,3 @@ clean:
165158
rm -f $(LIBRARY_LINK) $(LIBRARY) pacparser.o pactester pymod/pacparser_o_buildstamp jsapi_buildstamp
166159
rm -rf dist
167160
cd pymod && $(PYTHON) setup.py clean --all
168-
cd spidermonkey && $(MAKE) clean

src/Makefile.win32

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,32 @@ endif
3939
VERSION ?= $(shell git describe --always --tags --candidate=100)
4040

4141
LIB_VER=1
42-
CFLAGS=-g -DXP_WIN -DWINVER=0x0501 -DVERSION=$(VERSION) -Ispidermonkey/js/src -Wall
42+
CFLAGS=-g -DXP_WIN -DWINVER=0x0501 -DVERSION=$(VERSION) -Wall
4343
CC=gcc
4444
PYTHON ?= python
4545

4646
.PHONY: clean pymod install-pymod
4747

4848
all: pacparser.dll pactester
4949

50-
pacparser.o: pacparser.c pac_utils.h js.lib
50+
pacparser.o: pacparser.c pac_utils.h
5151
$(CC) $(CFLAGS) -c pacparser.c -o pacparser.o
5252

53-
js.lib:
54-
$(MAKE) -C spidermonkey -f Makefile.win32
53+
duktape.o: duktape.c duk_config.h duktape.h
54+
$(CC) $(CFLAGS) -c pacparser.c -o pacparser.o
5555

56-
pacparser.dll: pacparser.o spidermonkey/js.lib
56+
pacparser.dll: pacparser.o duktape.o
5757
$(CC) -shared -o pacparser.dll \
5858
-Wl,--output-def,pacparser.def \
5959
-Wl,--out-implib,libpacparser.a \
6060
-Wl,--export-all-symbols \
61-
pacparser.o -ljs -Lspidermonkey -lws2_32
61+
pacparser.o duktape.o -lws2_32
6262

6363
pacparser.lib: pacparser.dll pacparser.def
6464
lib /machine:i386 /def:pacparser.def
6565

6666
pactester: pactester.c pacparser.h pacparser.o
67-
$(CC) pactester.c pacparser.o -o pactester -ljs -Lspidermonkey -lws2_32
67+
$(CC) pactester.c pacparser.o duktape.o -o pactester -lws2_32
6868

6969
dist: pacparser.dll pactester pacparser.def
7070
if exist dist rmdir /s /q dist
@@ -98,7 +98,6 @@ pymod-dist-%:
9898
cd pymod && py -$* setup.py dist
9999

100100
clean:
101-
$(RM) pacparser.dll *.lib pacparser.def pacparser.exp pacparser.o pactester.exe libpacparser.a
102-
$(MAKE) -C spidermonkey -f Makefile.win32 clean
101+
$(RM) pacparser.dll *.lib pacparser.def pacparser.exp pacparser.o duktape.o pactester.exe libpacparser.a
103102
cd pymod && $(PYTHON) setup.py clean --all
104103
$(RM) dist

0 commit comments

Comments
 (0)