Files
lotherkandClaude Opus 5.5 6fe30f4787 security: the authorization model holds where the model writes the input
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>
2026-11-08 20:19:01 +00:00

101 lines
3.1 KiB
C

/*
* splinter -- UTF-8 to ASCII for the screen.
*
* The vendored curses mangles anything above 0x7f, so text is transliterated
* before drawing. The regression this test exists for: a hand-written table
* turned every character it did not know into '?', so a German answer full of
* typographic punctuation ("Gedankenstrich — Anfuehrungszeichen") arrived as a
* row of question marks.
*/
#include <stdio.h>
#include <string.h>
#include "ui.h"
static int failures;
#define CHECK(cond) do { \
if (!(cond)) { \
fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
failures++; \
} \
} while (0)
static int
no_questions(const char *s)
{
return strchr(s, '?') == NULL;
}
int
main(void)
{
char out[256];
/* ASCII survives untouched */
CHECK(sp_ui_ascii("hallo welt", out, sizeof(out)) == 0);
CHECK(strcmp(out, "hallo welt") == 0);
/* umlauts become something readable, not blocks */
CHECK(sp_ui_ascii("grün weiß schön", out, sizeof(out)) == 0);
CHECK(no_questions(out));
CHECK(strstr(out, "gr") != NULL && strstr(out, "sch") != NULL);
/* the typographic punctuation that used to produce ????? */
CHECK(sp_ui_ascii("ein — Gedankenstrich, „Zitat“, Auslassung…", out,
sizeof(out)) == 0);
CHECK(no_questions(out));
CHECK(strstr(out, "Gedankenstrich") != NULL);
CHECK(strstr(out, "Zitat") != NULL);
/* an ellipsis is not dropped silently */
CHECK(sp_ui_ascii("warten…", out, sizeof(out)) == 0);
CHECK(strlen(out) >= 6);
/* something genuinely unrepresentable becomes one '?', not a crash */
CHECK(sp_ui_ascii("a\U0001F600b", out, sizeof(out)) == 0);
CHECK(strlen(out) >= 2);
CHECK(strchr(out, 'a') != NULL && strchr(out, 'b') != NULL);
/* empty and NULL are handled */
CHECK(sp_ui_ascii("", out, sizeof(out)) == 0);
CHECK(strcmp(out, "") == 0);
CHECK(sp_ui_ascii(NULL, out, sizeof(out)) == -1);
/* a too-small buffer reports failure instead of writing past its end */
{
char small[8];
(void)sp_ui_ascii("abcdefghijklmnop", small, sizeof(small));
CHECK(strlen(small) < sizeof(small));
}
/*
* ---- one character at a time, as the history window draws it ----
* A three- or four-byte character used to be copied into a char[2].
* Under -fsanitize=address this block is what catches it.
*/
{
const char *dash = "\xe2\x80\x94x"; /* em dash, 3 bytes */
const char *ell = "\xe2\x80\xa6"; /* ellipsis */
const char *emoji = "\xf0\x9f\x98\x80y"; /* U+1F600, 4 bytes */
const char *cut = "\xf0\x9f"; /* truncated */
char one[8];
CHECK(sp_ui_ascii_char(dash, one, sizeof(one)) == 3);
CHECK(one[0] != '\0' && strlen(one) < sizeof(one));
CHECK(sp_ui_ascii_char(ell, one, sizeof(one)) == 3);
CHECK(no_questions(one));
CHECK(sp_ui_ascii_char(emoji, one, sizeof(one)) == 4);
CHECK(sp_ui_ascii_char(emoji + 4, one, sizeof(one)) == 1);
CHECK(strcmp(one, "y") == 0);
CHECK(sp_ui_ascii_char(cut, one, sizeof(one)) == 2);
CHECK(sp_ui_ascii_char("", one, sizeof(one)) == 0);
CHECK(sp_ui_ascii_char("\xc3\xbc", one, sizeof(one)) == 2);
}
if (failures == 0)
printf("test_ascii: ok\n");
return failures == 0 ? 0 : 1;
}