From c7b9bcd0ae15fa47c153bfc2d6227ff2c3d12bcd Mon Sep 17 00:00:00 2001 From: lotherk Date: Sun, 15 Nov 2026 04:56:03 +0000 Subject: [PATCH] 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 --- lib/McdeSys/linux.c | 3 +-- lib/McdeSys/net.c | 15 +++++++++++++++ lib/McdeSys/private.h | 2 ++ lib/McdeSys/test_netinput.c | 13 +++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/McdeSys/linux.c b/lib/McdeSys/linux.c index 74d913c1..d719d178 100644 --- a/lib/McdeSys/linux.c +++ b/lib/McdeSys/linux.c @@ -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; diff --git a/lib/McdeSys/net.c b/lib/McdeSys/net.c index 02190dff..77692989 100644 --- a/lib/McdeSys/net.c +++ b/lib/McdeSys/net.c @@ -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) diff --git a/lib/McdeSys/private.h b/lib/McdeSys/private.h index a27f1576..d77656f0 100644 --- a/lib/McdeSys/private.h +++ b/lib/McdeSys/private.h @@ -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 diff --git a/lib/McdeSys/test_netinput.c b/lib/McdeSys/test_netinput.c index 14f7d81c..553dcaed 100644 --- a/lib/McdeSys/test_netinput.c +++ b/lib/McdeSys/test_netinput.c @@ -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"));