sysupgrade-1.5 fetches with ftp and unpacks with tar as root and checks nothing; pkg_add -uu trusts the packages it is given (docs/reference/update-verification.txt). mcde_sys_update_source_ok (common.c, fail closed: the scheme in lower case, only [A-Za-z0-9._~:/@%+,=-]) is asked by mcde_sys_update_check, which then does not even contact a refused source, and by mcde_sys_update_apply, which refuses before any root action. http://, ftp://, ssh:// and shell or query characters are out. Measured: make mcde-linux MCDE_DIRS='check lib/McdeSys' exit=0, PASS 3 of 3 (test_updatesource has 28 cases, build/logs/mcde-linux-2026-11-14-t0078.log); netbsd.c does not build on this host, its update section compiled alone with -Wall -Wextra gives no warning. This does not verify any signature: that needs a key and Konrad's decision (t0078 steps 2 and 3). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
78 lines
2.3 KiB
C
78 lines
2.3 KiB
C
/*
|
|
* test_updatesource.c -- McdeSys: which update sources root may use (make check)
|
|
*
|
|
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
*
|
|
* The root update runs sysupgrade(8), which unpacks the sets and checks
|
|
* nothing, and pkg_add -uu on the packages it is given. With an http://
|
|
* source anyone on the way could replace them, so only a directory, file:///
|
|
* and https:// are accepted (tasksd t0078, docs/reference/
|
|
* update-verification.txt). The other characters keep a source from meaning
|
|
* more than a place to a shell, an option or a URL query.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include <Mcde/McdeSys.h>
|
|
|
|
#include "private.h" /* mcde_sys_update_source_ok: the library's, not the API */
|
|
|
|
static const struct {
|
|
const char *url;
|
|
int ok;
|
|
} cases[] = {
|
|
{ "/mnt/release", 1 }, /* a directory */
|
|
{ "/home/user/makronix-0.99.10", 1 },
|
|
{ "file:///mnt/release", 1 },
|
|
{ "https://updates.example.org/makronix/0.99", 1 },
|
|
{ "https://updates.example.org:8443/m", 1 },
|
|
{ "https://10.0.0.5/m", 1 },
|
|
/* refused: the way can be read and changed */
|
|
{ "http://updates.example.org/makronix", 0 },
|
|
{ "HTTP://updates.example.org/makronix", 0 },
|
|
{ "ftp://updates.example.org/makronix", 0 },
|
|
{ "ssh://root@host/makronix", 0 },
|
|
{ "HTTPS://updates.example.org/m", 0 }, /* only the form sysupgrade knows */
|
|
{ "https://", 0 }, /* no host */
|
|
{ "https:///m", 0 },
|
|
{ "file://host/m", 0 }, /* a remote "file" */
|
|
{ "file:/mnt/release", 0 },
|
|
{ "relative/dir", 0 },
|
|
{ "-oProxyCommand=id", 0 }, /* an option, not a place */
|
|
{ "", 0 },
|
|
/* refused: characters that mean something */
|
|
{ "/mnt/release; reboot", 0 },
|
|
{ "/mnt/rel ease", 0 },
|
|
{ "/mnt/$(id)", 0 },
|
|
{ "/mnt/`id`", 0 },
|
|
{ "https://host/m?x=1&y=2", 0 },
|
|
{ "https://host/m#frag", 0 },
|
|
{ "/mnt/it's", 0 },
|
|
{ "/mnt/a\nb", 0 },
|
|
{ "/mnt/a\\b", 0 },
|
|
};
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
size_t i;
|
|
int failures = 0, ok;
|
|
|
|
if (mcde_sys_update_source_ok(NULL) != 0) {
|
|
printf("FAIL NULL: accepted\n");
|
|
failures++;
|
|
}
|
|
for (i = 0; i < sizeof cases / sizeof cases[0]; i++) {
|
|
ok = mcde_sys_update_source_ok(cases[i].url) != 0;
|
|
if (ok != cases[i].ok) {
|
|
printf("FAIL \"%s\": %s\n", cases[i].url,
|
|
ok ? "accepted" : "refused");
|
|
failures++;
|
|
}
|
|
}
|
|
printf("test_updatesource: %d cases, %d failures\n",
|
|
(int) (sizeof cases / sizeof cases[0]) + 1, failures);
|
|
return failures != 0;
|
|
}
|