McdeSys: an sftp user that starts with "-" no longer reaches sshfs as an option (t0081, tests)

ParseUrl refused a host that starts with "-" but not a user: the first argument
of sshfs is "USER@HOST:PATH", so sftp://-p22@host/ gave it "-p22@host:/", an
option.  Found by the table test this commit adds: mcde_sys_net_url_ok (the
tests' view of ParseUrl, private.h) with 22 addresses -- sftp/nfs/afp, IPv6
written bare, an empty user, a user or host that is an option, a space, ';',
'$(id)', a second '@', a newline in the path, no host, no scheme, a scheme of 16
characters, a host of 255 (kept) and 256 (refused) characters, NULL.
Red before the fix: exactly sftp://-l@host/ and sftp://-p22@host/ accepted;
green after: make check 5 of 5 (34 ok lines in test_netmount).

Not done of t0081: the checks of mcde_sys_wifi_join (netbsd.c:534ff, SSID 33
bytes, quotes, backslash, passphrase 8..63) -- they come after geteuid() != 0
and are NetBSD-only (the Linux branch checks the length only and must keep
quotes in a passphrase), so no test of the build can reach them without a
shared validator; catalogs and @PREFIX@ untouched.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
lotherkandClaude Sonnet 5.5 committed 2026-11-15 00:58:27 +00:00
1 parent 076cb486d6
commit bd41face71
3 files changed
+80 -1

No files matched your search

+12 -1
View File
@@ -142,11 +142,22 @@ ParseUrl(const char *url, char *scheme, char *user, char *host, char *path)
snprintf(host, 256, "%.*s", (int) n, p);
if (slash != NULL)
snprintf(path, 512, "%s", slash);
return GoodHost(host) &&
/* a user that starts with "-" would be an option of sshfs: its first
* argument is "USER@HOST:PATH" (as a host may not start with "-") */
return GoodHost(host) && user[0] != '-' &&
strspn(user, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789._-") == strlen(user) && strchr(path, '\n') == NULL;
}
/* 1 when URL would reach a command line (the tests' view of ParseUrl) */
int
mcde_sys_net_url_ok(const char *url)
{
char scheme[16], user[64], host[256], path[512];
return url != NULL && ParseUrl(url, scheme, user, host, path);
}
/* the command that connects URL to MOUNTPOINT: the tool, its arguments, and
* what goes to its standard input (a password for sshfs). Kept in one
* structure so that mcde_sys_net_mount (waits) and mcde_sys_net_mount_start
+2
View File
@@ -98,6 +98,8 @@ const char *mcde_sys_afp_conf(void);
void mcde_sys_export_line(const char *path, char *buf, size_t len);
/* the backend: make running servers read their configuration again */
void mcde_sys_shares_reload(void);
/* netmount.c: would URL (sftp://, nfs://, afp://) reach a command line */
int mcde_sys_net_url_ok(const char *url);
/* netmount.c: a service of KIND found on HOST (NAME as it calls itself)
* into HOSTS, merged by host; the new count */
int mcde_sys_net_add(McdeSysNetHost *hosts, int n, size_t max,
+66
View File
@@ -34,6 +34,38 @@ static const struct {
{ ".", 0 }, /* empty after the dot */
};
/* the address a person types (or a favourite holds): what may reach sshfs,
* mount_nfs and mount_afp as an argument (review 2026-11-13, tasksd t0081).
* The sftp tool gets "USER@HOST:PATH" as its first argument, so a USER that
* starts with "-" would be an option. */
static const struct {
const char *url;
int ok;
} urls[] = {
{ "sftp://host/", 1 },
{ "sftp://user@host/path", 1 },
{ "sftp://u.ser-1_x@10.0.0.1/p/q", 1 },
{ "nfs://server.local/export", 1 },
{ "afp://user@host/Volume", 1 },
{ "sftp://fe80::1/x", 1 }, /* IPv6 written bare */
{ "sftp://@host/", 1 }, /* an empty user: none */
{ "sftp://-oProxyCommand=id/", 0 }, /* a host that is an option */
{ "sftp://user@-host/", 0 },
{ "sftp://-l@host/", 0 }, /* a user that is an option */
{ "sftp://-p22@host/", 0 },
{ "sftp://us er@host/", 0 },
{ "sftp://user;id@host/", 0 },
{ "sftp://user@host name/", 0 },
{ "sftp://host/a\nb", 0 }, /* a newline in the path */
{ "sftp:///path", 0 }, /* no host */
{ "sftp://", 0 },
{ "host/path", 0 }, /* no scheme */
{ "abcdefghijklmnop://host/", 0 }, /* a scheme of 16 characters */
{ "sftp://user@host@evil/", 0 },
{ "sftp://host$(id)/", 0 },
{ "", 0 },
};
int
main(void)
{
@@ -41,6 +73,40 @@ main(void)
size_t i;
int failures = 0, n;
for (i = 0; i < sizeof urls / sizeof urls[0]; i++) {
n = mcde_sys_net_url_ok(urls[i].url) != 0;
if (n != urls[i].ok) {
printf("FAIL url \"%s\": %s\n", urls[i].url,
n ? "accepted" : "refused");
failures++;
} else
printf("ok url \"%s\": %s\n", urls[i].url,
n ? "accepted" : "refused");
}
/* a host of 256 characters and one of 255 */
{
char long_url[320];
memset(long_url, 0, sizeof long_url);
strcpy(long_url, "sftp://");
memset(long_url + 7, 'a', 256);
strcat(long_url, "/");
if (mcde_sys_net_url_ok(long_url)) {
printf("FAIL a host of 256 characters accepted\n");
failures++;
}
long_url[7 + 255] = '\0';
strcat(long_url, "/");
if (!mcde_sys_net_url_ok(long_url)) {
printf("FAIL a host of 255 characters refused\n");
failures++;
}
}
if (mcde_sys_net_url_ok(NULL)) {
printf("FAIL NULL accepted\n");
failures++;
}
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);