A review found the tool classes - the core of the harness - bypassable in
several places where model output was pasted into a shell or trusted as an id.
Each fix below has a test that reproduces the original failure.
No shell for model data
- webfetch put the URL between '...' and ran it through popen: a quote in the
URL ran any command, from a tool that needed no consent. curl is now exec'd
with an argv, http(s) only, HTML stripped in C, stderr off the curses screen.
- webfetch is mutate: with read free, "read a key, fetch evil/?k=..." left the
machine without anybody being asked. websearch stays read (fixed host).
- kids: the parent-approval command got the model's arguments inside '...'
via system(); they are now "$1". The domain check reads the URL with the
same parser as the tool (duplicate keys) and refuses user@host URLs.
- delegate: the two copies of the child argv are one (exec_delegate). The ssh
path exec'd splinter with "ssh" as argv[0]; it now runs ssh and quotes every
word for the remote shell. A single delegate to a host now really runs there.
Approvals (ack)
- The id was the pid: a late yes stayed on disk and approved the next request
unseen. Ids are random, requests 0600 with O_EXCL, deleted when answered or
expired; an answer is refused after expiry; the first answer wins (link(2)).
- An ack dir owned by someone else or writable by others is refused.
- --ack accepted every word but "no" as yes ("nein" approved). Now strict.
- The terminal thread blocked in fgets after a phone answer; it is stoppable.
Secrets
- API key and Telegram token were in curl's argv, readable via ps. src/curl.c
passes URL and auth headers as a -K config on stdin (transport, telegram,
tg-ask.sh; its dead eval fallback is gone).
- 'run' and task_start no longer inherit splinter's keys ("run env"). 'run' got
its own process group, stdin /dev/null and SPLINTER_RUN_TIMEOUT (300 s).
MCP server
- Beyond 127.x it refuses to start without SPLINTER_MCP_TOKEN; connections
must begin with "AUTH <token>". SIGPIPE ignored, idle connections closed.
Crashes
- task_kill sent kill(-0) - SIGTERM to splinter's own process group - because
popen gave no pid. Tasks now have a pid and a process group; integer ids work.
- ui: a 3- or 4-byte UTF-8 character overflowed char[2] on every redraw
(now sp_ui_ascii_char, tested); the scroll offset was taken from one buffer
and applied to another, reading past its end.
Repo
- The test binaries are no longer tracked (.gitignore already said so).
make check: 23 test binaries, green, also under ASan/UBSan.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
209 lines
9.9 KiB
Makefile
209 lines
9.9 KiB
Makefile
# splinter -- POSIX make for our own code, GNU make only for the vendored curses.
|
|
#
|
|
# make libsplinter.so, the splinter binary, the example plugin
|
|
# make check builds and runs every test binary
|
|
# make curses builds the vendored NetBSD curses explicitly
|
|
# make clean removes generated files only
|
|
#
|
|
# The layout is deliberate: all logic lives in libsplinter.so. The binary and
|
|
# every plugin link against that one library, so there is exactly one copy of
|
|
# each symbol in the process. Two copies would mean two registries.
|
|
|
|
CC ?= cc
|
|
CFLAGS ?= -std=c99 -O2 -Wall -Wextra -Werror -D_POSIX_C_SOURCE=200809L \
|
|
-fPIC -Iinclude -Isrc -Ivendor/libmcp -Ivendor/netbsd-curses/libcurses
|
|
LDFLAGS ?=
|
|
LIBS ?= -lpthread
|
|
PREFIX ?= /usr/local
|
|
|
|
CURSES_DIR = vendor/netbsd-curses
|
|
CURSES_A = $(CURSES_DIR)/libcurses/libcurses.a \
|
|
$(CURSES_DIR)/libterminfo/libterminfo.a
|
|
|
|
LIB = libsplinter.so
|
|
LIBOBJ = src/buf.o src/tool.o src/session.o src/conv.o src/transport.o \
|
|
src/json.o src/sse.o src/openai.o src/transport_openai.o src/builtin.o \
|
|
src/agent.o src/theme.o src/palettes.o src/decomp.o src/i18n.o src/delegate.o src/telegram.o src/log.o src/cmdscript.o src/folder.o src/interview.o src/ack.o src/mcpserver.o src/skills.o src/memory.o src/prompt.o src/config.o src/plugin.o src/curl.o
|
|
BIN = splinter
|
|
BINOBJ = src/main.o src/ui.o
|
|
PLUGIN = plugins/clock/clock.so plugins/lcm/lcm.so plugins/cps/cps.so \
|
|
plugins/cli/cli.so plugins/focus/focus.so plugins/mcp/mcp.so \
|
|
plugins/ring/ring.so plugins/reminder/reminder.so \
|
|
plugins/kids/kids.so plugins/status/status.so plugins/tasks/tasks.so
|
|
TESTS = tests/test_buf tests/test_tool tests/test_session tests/test_conv \
|
|
tests/test_transport tests/test_agent tests/test_openai \
|
|
tests/test_theme tests/test_plugin tests/test_memory tests/test_skills tests/test_telegram tests/test_delegate tests/test_builtin tests/test_ascii tests/test_ack tests/test_i18n tests/test_config tests/test_focus tests/test_sse tests/test_cli tests/test_compactor tests/test_secrets
|
|
|
|
RPATH = -Wl,-rpath,'$$ORIGIN'
|
|
PLUGIN_RPATH = -Wl,-rpath,'$$ORIGIN/../..'
|
|
TEST_RPATH = -Wl,-rpath,'$$ORIGIN/..'
|
|
|
|
all: $(LIB) $(BIN) $(PLUGIN)
|
|
|
|
# The vendored tree ships a GNUmakefile; this is the only place that needs GNU
|
|
# make, and it is why the comment above says so out loud.
|
|
$(CURSES_A):
|
|
cd $(CURSES_DIR) && $(MAKE) -f GNUmakefile libcurses/libcurses.a \
|
|
libterminfo/libterminfo.a
|
|
|
|
curses: $(CURSES_A)
|
|
|
|
$(LIB): $(LIBOBJ) $(CURSES_A)
|
|
$(CC) -shared -o $@ $(LIBOBJ) $(CURSES_A) $(LIBS)
|
|
|
|
# curses belongs to the front end, not to the library: a plugin that drew into
|
|
# a WINDOW would be a plugin holding the UI thread's state.
|
|
$(BIN): $(BINOBJ) $(LIB)
|
|
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(BINOBJ) -L. -lsplinter $(RPATH) \
|
|
$(CURSES_A) $(LIBS)
|
|
|
|
plugins/clock/clock.so: plugins/clock/clock.c $(LIB)
|
|
$(CC) $(CFLAGS) -shared -o $@ plugins/clock/clock.c -L. -lsplinter \
|
|
$(PLUGIN_RPATH) $(LIBS)
|
|
|
|
plugins/lcm/lcm.so: plugins/lcm/lcm.c $(LIB)
|
|
$(CC) $(CFLAGS) -shared -o $@ plugins/lcm/lcm.c -L. -lsplinter \
|
|
$(PLUGIN_RPATH) $(LIBS)
|
|
|
|
plugins/cli/cli.so: plugins/cli/cli.c $(LIB)
|
|
$(CC) $(CFLAGS) -shared -o $@ plugins/cli/cli.c -L. -lsplinter \
|
|
$(PLUGIN_RPATH) $(LIBS)
|
|
|
|
plugins/ring/ring.so: plugins/ring/ring.c $(LIB)
|
|
$(CC) $(CFLAGS) -shared -o $@ plugins/ring/ring.c -L. -lsplinter \
|
|
-Iinclude -Isrc -Ivendor/libmcp $(PLUGIN_LDFLAGS)
|
|
plugins/kids/kids.so: plugins/kids/kids.c $(LIB)
|
|
$(CC) $(CFLAGS) -shared -o $@ plugins/kids/kids.c -L. -lsplinter \
|
|
-Iinclude -Isrc -Ivendor/libmcp $(PLUGIN_LDFLAGS)
|
|
plugins/tasks/tasks.so: plugins/tasks/tasks.c $(LIB)
|
|
$(CC) $(CFLAGS) -shared -o $@ plugins/tasks/tasks.c -L. -lsplinter \
|
|
-Iinclude -Isrc -Ivendor/libmcp $(PLUGIN_LDFLAGS)
|
|
plugins/status/status.so: plugins/status/status.c $(LIB)
|
|
$(CC) $(CFLAGS) -shared -o $@ plugins/status/status.c -L. -lsplinter \
|
|
-Iinclude -Isrc -Ivendor/libmcp $(PLUGIN_LDFLAGS)
|
|
plugins/reminder/reminder.so: plugins/reminder/reminder.c $(LIB)
|
|
$(CC) $(CFLAGS) -shared -o $@ plugins/reminder/reminder.c -L. -lsplinter \
|
|
-Iinclude -Isrc -Ivendor/libmcp $(PLUGIN_LDFLAGS)
|
|
plugins/mcp/mcp.so: plugins/mcp/mcp.c $(LIB)
|
|
$(CC) $(CFLAGS) -shared -o $@ plugins/mcp/mcp.c -L. -lsplinter \
|
|
-Iinclude -Isrc -Ivendor/libmcp $(PLUGIN_LDFLAGS)
|
|
plugins/focus/focus.so: plugins/focus/focus.c $(LIB)
|
|
$(CC) $(CFLAGS) -shared -o $@ plugins/focus/focus.c -L. -lsplinter \
|
|
$(PLUGIN_RPATH) $(LIBS)
|
|
|
|
plugins/cps/cps.so: plugins/cps/cps.c $(LIB)
|
|
$(CC) $(CFLAGS) -shared -o $@ plugins/cps/cps.c -L. -lsplinter \
|
|
$(PLUGIN_RPATH) $(LIBS)
|
|
|
|
.c.o:
|
|
$(CC) $(CFLAGS) -c -o $@ $<
|
|
|
|
src/agent.o: include/splinter.h
|
|
src/buf.o: include/splinter.h
|
|
src/tool.o: include/splinter.h
|
|
src/session.o: include/splinter.h
|
|
src/transport.o: include/splinter.h
|
|
src/conv.o: include/splinter.h
|
|
src/json.o: vendor/libmcp/mcp.h
|
|
src/sse.o: include/splinter.h vendor/libmcp/mcp.h
|
|
src/openai.o: include/splinter.h vendor/libmcp/mcp.h
|
|
src/transport_openai.o: include/splinter.h src/curl.h src/log.h
|
|
src/curl.o: src/curl.h include/splinter.h
|
|
src/builtin.o: include/splinter.h
|
|
src/theme.o: src/theme.h src/palettes.h include/splinter.h
|
|
src/palettes.o: src/palettes.h
|
|
src/decomp.o: src/decomp.h
|
|
src/i18n.o: src/i18n.h include/splinter.h
|
|
src/delegate.o: src/config.h include/splinter.h
|
|
src/telegram.o: include/splinter.h src/curl.h src/ack.h
|
|
src/log.o: src/log.h
|
|
src/cmdscript.o: src/cmdscript.h include/splinter.h
|
|
src/folder.o: src/folder.h include/splinter.h
|
|
src/ack.o: src/ack.h include/splinter.h
|
|
src/interview.o: src/interview.h include/splinter.h
|
|
src/mcpserver.o: src/mcpserver.h include/splinter.h
|
|
src/skills.o: src/skills.h src/config.h include/splinter.h
|
|
src/prompt.o: src/prompt.h include/splinter.h
|
|
src/memory.o: src/memory.h src/config.h include/splinter.h
|
|
src/config.o: src/config.h include/splinter.h
|
|
src/plugin.o: include/splinter.h include/splinter_plugin.h
|
|
src/ui.o: src/ui.h src/theme.h src/decomp.h src/i18n.h include/splinter.h include/splinter_plugin.h
|
|
src/main.o: include/splinter.h src/config.h src/i18n.h include/splinter_plugin.h src/ui.h src/theme.h
|
|
|
|
tests/test_buf: tests/test_buf.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_buf.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_tool: tests/test_tool.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_tool.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_session: tests/test_session.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_session.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_transport: tests/test_transport.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_transport.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_agent: tests/test_agent.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_agent.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_conv: tests/test_conv.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_conv.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_openai: tests/test_openai.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_openai.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_theme: tests/test_theme.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_theme.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_focus: tests/test_focus.c $(LIB) $(PLUGIN)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_focus.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_memory: tests/test_memory.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_memory.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_skills: tests/test_skills.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_skills.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_telegram: tests/test_telegram.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_telegram.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_delegate: tests/test_delegate.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_delegate.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_builtin: tests/test_builtin.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_builtin.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_ack: tests/test_ack.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_ack.c -L. -lsplinter \
|
|
-Iinclude -Isrc $(PLUGIN_LDFLAGS)
|
|
tests/test_i18n: tests/test_i18n.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_i18n.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_ascii: tests/test_ascii.c $(LIB) $(BINOBJ)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_ascii.c src/ui.o -L. -lsplinter \
|
|
$(TEST_RPATH) $(CURSES_A) $(LIBS)
|
|
tests/test_config: tests/test_config.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_config.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_sse: tests/test_sse.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_sse.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_cli: tests/test_cli.c $(LIB) $(PLUGIN)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_cli.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
|
|
tests/test_compactor: tests/test_compactor.c $(LIB) $(PLUGIN)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_compactor.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_secrets: tests/test_secrets.c $(LIB) $(PLUGIN)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_secrets.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_plugin: tests/test_plugin.c $(LIB) $(PLUGIN)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_plugin.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
|
|
check: $(LIB) $(BIN) $(PLUGIN) $(TESTS)
|
|
@set -e; python3 tools/check_i18n.py; python3 tools/gen_www.py --check; \
|
|
export LD_LIBRARY_PATH=.; \
|
|
for t in $(TESTS); do echo "== $$t"; ./$$t; done; \
|
|
echo "all tests passed"
|
|
|
|
# The installed binary finds its own library through an rpath relative to itself
|
|
# ($ORIGIN), so 'make install PREFIX=$HOME/.local' produces a program that runs
|
|
# without a wrapper, without LD_LIBRARY_PATH and without an environment file.
|
|
install: all
|
|
mkdir -p $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(PREFIX)/lib
|
|
$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-rpath,'$$ORIGIN/../lib' \
|
|
-o $(DESTDIR)$(PREFIX)/bin/splinter $(BINOBJ) -L. -lsplinter \
|
|
$(CURSES_A) $(LIBS)
|
|
cp $(LIB) $(DESTDIR)$(PREFIX)/lib/
|
|
@echo "installed $(DESTDIR)$(PREFIX)/bin/splinter"
|
|
|
|
clean:
|
|
rm -f $(BIN) $(LIB) $(LIBOBJ) $(BINOBJ) $(PLUGIN) $(TESTS)
|
|
|
|
.PHONY: all check curses install clean
|
|
|
|
# The pages are generated: one source, every language, and a missing translation
|
|
# is a hard error - the same rule as the program's own catalogues.
|
|
www:
|
|
python3 tools/gen_www.py
|