Review 2026-11-13 (tasksd t0076): dtfile's network view ran
system("dtterm -title '%s' -e ssh '%s' &") with the mDNS service name and
host target, and its comment said McdeSys had checked the host -- it had
not: mcde_sys_net_add() only copied it. A host advertising _ssh._tcp with
the target "-oProxyCommand=..." reached ssh as an option, and ssh runs a
ProxyCommand through a shell.
- netmount.c mcde_sys_net_add(): GoodHost() once for every name from the
network (no leading -, letters/digits/. - _ : only); control characters
in the free-text service name become ?.
- NetView.c: SshTerminal() forks and execs dtterm -e ssh -- HOST, no shell,
detached by a second fork (daemon(3) pattern); no system() is left in
the MCDE programs.
- test_netmount (make check): 12 host names, kept or dropped as expected,
and the control character; PASS with test_sysinfo
(build/logs/mcde-linux-netview-2026-11-13.log; dtfile builds).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
1.7 KiB
C
64 lines
1.7 KiB
C
/*
|
|
* test_netmount.c -- McdeSys: which host names reach the list (make check)
|
|
*
|
|
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
|
|
*
|
|
* mcde_sys_net_add() is where a name from the network (mDNS, a browse) is
|
|
* checked once for every program that opens it: a host beginning with "-"
|
|
* would reach ssh or a mount tool as an option, a quote or a blank would
|
|
* reach a shell (review 2026-11-13, tasksd t0076).
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include <Mcde/McdeSys.h>
|
|
|
|
#include "private.h" /* mcde_sys_net_add: the library's, not the API */
|
|
|
|
static const struct {
|
|
const char *host;
|
|
int kept;
|
|
} cases[] = {
|
|
{ "kitt.local.", 1 }, /* the trailing dot goes */
|
|
{ "kitt.local", 1 },
|
|
{ "fe80::1", 1 }, /* IPv6 */
|
|
{ "-oProxyCommand=touch${IFS}/tmp/x.local", 0 },
|
|
{ "-l", 0 },
|
|
{ "host;id", 0 },
|
|
{ "host name", 0 },
|
|
{ "it's", 0 },
|
|
{ "a\nb", 0 },
|
|
{ "$(id)", 0 },
|
|
{ "", 0 },
|
|
{ ".", 0 }, /* empty after the dot */
|
|
};
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
McdeSysNetHost hosts[4];
|
|
size_t i;
|
|
int failures = 0, n;
|
|
|
|
for (i = 0; i < sizeof cases / sizeof cases[0]; i++) {
|
|
n = mcde_sys_net_add(hosts, 0, 4, "name", cases[i].host,
|
|
MCDE_NET_HAS_SSH);
|
|
if (n != cases[i].kept) {
|
|
printf("FAIL \"%s\": %s\n", cases[i].host,
|
|
n ? "kept" : "dropped");
|
|
failures++;
|
|
} else
|
|
printf("ok \"%s\": %s\n", cases[i].host,
|
|
n ? "kept" : "dropped");
|
|
}
|
|
/* the service name is free text: no control characters on screen */
|
|
n = mcde_sys_net_add(hosts, 0, 4, "evil\033[2Jname", "kitt.local",
|
|
MCDE_NET_HAS_SSH);
|
|
if (n != 1 || strchr(hosts[0].name, '\033') != NULL) {
|
|
printf("FAIL control character in the name\n");
|
|
failures++;
|
|
}
|
|
return failures != 0;
|
|
}
|