Files
lotherkandClaude Sonnet 5.5 c7b9bcd0ae 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>
2026-11-15 04:56:03 +00:00

113 lines
4.6 KiB
C

/*
* test_netinput.c -- McdeSys: what may reach a network command or a file (make check)
*
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
*
* The checks that stand between a typed network name or password and
* wpa_supplicant.conf, rc.conf and the command lines of the network tools
* (review 2026-11-13, tasksd t0081): the Wi-Fi network (a name of 33 bytes, a
* quote, a backslash or a newline would end the quoted string of the file or
* add a line to it), the interface name, the netmask.
*/
#include <stdio.h>
#include <string.h>
#include <Mcde/McdeSys.h>
#include "private.h" /* the library's checks, not the API */
static int failures;
#define CHECK(cond) do { \
if (!(cond)) { \
printf("FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
failures++; \
} \
} while (0)
int
main(void)
{
char s32[33], s33[34], p63[64], p64[65], p7[8], p8[9];
memset(s32, 'n', 32); s32[32] = '\0';
memset(s33, 'n', 33); s33[33] = '\0';
memset(p63, 'p', 63); p63[63] = '\0';
memset(p64, 'p', 64); p64[64] = '\0';
memset(p7, 'p', 7); p7[7] = '\0';
memset(p8, 'p', 8); p8[8] = '\0';
/* the network: name 1..32 bytes, passphrase none or 8..63 */
CHECK(mcde_sys_wifi_config_ok("iwn0", "Home", "hunter22"));
CHECK(mcde_sys_wifi_config_ok("wlan0", "Home Network", NULL)); /* open */
CHECK(mcde_sys_wifi_config_ok("iwn0", "caf\xc3\xa9", "pass word"));
CHECK(mcde_sys_wifi_config_ok("iwn0", s32, p63)); /* the longest */
CHECK(mcde_sys_wifi_config_ok("iwn0", "a", p8)); /* the shortest */
CHECK(!mcde_sys_wifi_config_ok("iwn0", s33, p8)); /* name 33 bytes */
CHECK(!mcde_sys_wifi_config_ok("iwn0", "", p8)); /* no name */
CHECK(!mcde_sys_wifi_config_ok("iwn0", NULL, p8));
CHECK(!mcde_sys_wifi_config_ok("iwn0", "Home", p7)); /* 7 */
CHECK(!mcde_sys_wifi_config_ok("iwn0", "Home", p64)); /* 64 */
CHECK(!mcde_sys_wifi_config_ok("iwn0", "Home", ""));
/* what would end the quoted string or add a line to the file */
CHECK(!mcde_sys_wifi_config_ok("iwn0", "a\"b", p8));
CHECK(!mcde_sys_wifi_config_ok("iwn0", "a\\b", p8));
CHECK(!mcde_sys_wifi_config_ok("iwn0", "a\nb", p8));
CHECK(!mcde_sys_wifi_config_ok("iwn0", "Home\"\n}\nnetwork={ssid=\"x", p8));
CHECK(!mcde_sys_wifi_config_ok("iwn0", "Home", "pass\"word1"));
CHECK(!mcde_sys_wifi_config_ok("iwn0", "Home", "pass\\word1"));
CHECK(!mcde_sys_wifi_config_ok("iwn0", "Home", "pass\nword1"));
CHECK(!mcde_sys_wifi_config_ok("iwn0", "Home",
"12345678\"\n\tkey_mgmt=NONE"));
/* the interface name goes into rc.conf: lower case and digits only */
CHECK(mcde_sys_wifi_config_ok("urtwn0", "Home", p8));
CHECK(!mcde_sys_wifi_config_ok(NULL, "Home", p8));
CHECK(!mcde_sys_wifi_config_ok("", "Home", p8)); /* was accepted */
CHECK(!mcde_sys_wifi_config_ok("iwn0 -x", "Home", p8));
CHECK(!mcde_sys_wifi_config_ok("iwn0;id", "Home", p8));
CHECK(!mcde_sys_wifi_config_ok("-iwn0", "Home", p8));
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"));
CHECK(mcde_sys_net_ifname_ok("br-lan"));
CHECK(!mcde_sys_net_ifname_ok(NULL));
CHECK(!mcde_sys_net_ifname_ok(""));
CHECK(!mcde_sys_net_ifname_ok("-i"));
CHECK(!mcde_sys_net_ifname_ok("eth0 x"));
CHECK(!mcde_sys_net_ifname_ok("eth0;id"));
CHECK(!mcde_sys_net_ifname_ok("a\nb"));
CHECK(!mcde_sys_net_ifname_ok("0123456789abcdef")); /* IFNAMSIZ */
/* a netmask: contiguous ones only */
CHECK(mcde_sys_net_prefix("255.255.255.0") == 24);
CHECK(mcde_sys_net_prefix("255.255.255.255") == 32);
CHECK(mcde_sys_net_prefix("255.255.254.0") == 23);
CHECK(mcde_sys_net_prefix("0.0.0.0") == 0);
CHECK(mcde_sys_net_prefix("255.0.255.0") == -1);
CHECK(mcde_sys_net_prefix("255.255.255.1") == -1);
CHECK(mcde_sys_net_prefix("24") == -1);
CHECK(mcde_sys_net_prefix("255.255.255.0; id") == -1);
CHECK(mcde_sys_net_prefix("") == -1);
if (failures == 0)
printf("test_netinput: all passed\n");
return failures != 0;
}