McdeSys: a Wi-Fi name that starts with "-" is no argument for nmcli (t0081)

The Linux mcde_sys_wifi_join passes the network name to
"nmcli device wifi connect NAME ...".  The name of an access point is what the
neighbour's device broadcasts.  Measured with nmcli 1.56.1:
  nmcli device wifi connect --ask password PW ifname IF
  -> "Error: invalid extra argument 'PW'" -- the name was taken as the option
  --ask (a name of -x, --help or - is taken as a name; no effect).
"--" in front is no remedy: nmcli takes the "--" for the name ("invalid extra
argument 'Home'" for a normal name).  The password is safe: it is the argument
of the keyword "password" whatever it starts with.

So the Linux branch refuses a name that starts with "-" (mcde_sys_wifi_ssid_arg_ok
in net.c, with the old 1..32 byte rule); the NetBSD branch does not call nmcli.
A legitimate network called "-something" cannot be joined from System Settings
on Linux; the message is the old one ("The network name cannot be used").
test_netinput: 11 more checks; make check 6 of 6; with the dash rule removed the
test fails (checked with a mutant).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
lotherkandClaude Sonnet 5.5 committed 2026-11-15 04:56:03 +00:00
1 parent 378a6bc805
commit c7b9bcd0ae
4 files changed
+31 -2

No files matched your search

+1 -2
View File
@@ -450,8 +450,7 @@ mcde_sys_wifi_join(const char *ifname, const char *ssid,
if (nm == NULL)
return mcde_sys_fail(MCDE_SYS_ENOTSUP, "NetworkManager (nmcli) "
"is not there.");
if (ifname == NULL || ssid == NULL || ssid[0] == '\0' ||
strlen(ssid) > 32)
if (ifname == NULL || !mcde_sys_wifi_ssid_arg_ok(ssid))
return mcde_sys_fail(MCDE_SYS_EINVAL, "The network name cannot "
"be used.");
argv[n++] = (char *) nm;
+15
View File
@@ -149,6 +149,21 @@ mcde_sys_wifi_config_ok(const char *ifname, const char *ssid,
return 1;
}
/* May this network name be a command-line argument of nmcli (the Linux
* mcde_sys_wifi_join)? 1 to 32 bytes, and not starting with "-": a name that
* does is an option to nmcli, and the name of a neighbour's access point is
* whatever it broadcasts. Measured with nmcli 1.56.1: "nmcli device wifi
* connect --ask password PW ifname IF" gives "invalid extra argument" -- the
* name was taken as the option --ask; and "--" in front is no remedy: nmcli
* takes the "--" for the name ("invalid extra argument 'Home'"). A passphrase
* is the argument of "password", whatever it starts with. */
int
mcde_sys_wifi_ssid_arg_ok(const char *ssid)
{
return ssid != NULL && ssid[0] != '\0' && ssid[0] != '-' &&
strlen(ssid) <= 32;
}
/* the prefix length of a dotted netmask, -1 when it is none */
int
mcde_sys_net_prefix(const char *netmask)
+2
View File
@@ -59,6 +59,8 @@ int mcde_sys_net_ifname_ok(const char *name);
* NetBSD mcde_sys_wifi_join); 1 if so */
int mcde_sys_wifi_config_ok(const char *ifname, const char *ssid,
const char *passphrase);
/* net.c: may this network name be an argument of nmcli (Linux wifi_join) */
int mcde_sys_wifi_ssid_arg_ok(const char *ssid);
int mcde_sys_net_prefix(const char *netmask);
void mcde_sys_net_mask(int prefix, char *buf, size_t len);
/* the backend: the configured settings of IFNAME, its router, Ethernet ID
+13
View File
@@ -70,6 +70,19 @@ main(void)
CHECK(!mcde_sys_wifi_config_ok("IWN0", "Home", p8));
CHECK(!mcde_sys_wifi_config_ok("iwn0\"", "Home", p8));
/* the name as an argument of nmcli (Linux): not an option */
CHECK(mcde_sys_wifi_ssid_arg_ok("Home"));
CHECK(mcde_sys_wifi_ssid_arg_ok("Home Network"));
CHECK(mcde_sys_wifi_ssid_arg_ok("a-b")); /* a dash inside is fine */
CHECK(mcde_sys_wifi_ssid_arg_ok("quote\"and\\ok")); /* nmcli is no file */
CHECK(mcde_sys_wifi_ssid_arg_ok(s32));
CHECK(!mcde_sys_wifi_ssid_arg_ok(s33));
CHECK(!mcde_sys_wifi_ssid_arg_ok(""));
CHECK(!mcde_sys_wifi_ssid_arg_ok(NULL));
CHECK(!mcde_sys_wifi_ssid_arg_ok("--ask")); /* measured: an option */
CHECK(!mcde_sys_wifi_ssid_arg_ok("-x"));
CHECK(!mcde_sys_wifi_ssid_arg_ok("-"));
/* an interface name for a command line (the settings pane) */
CHECK(mcde_sys_net_ifname_ok("iwn0"));
CHECK(mcde_sys_net_ifname_ok("eth0.100"));