The checks that keep a typed network name and password out of
wpa_supplicant.conf and rc.conf (netbsd.c, mcde_sys_wifi_join) sat inline in
the NetBSD branch, behind geteuid() != 0: no test of the build could run them.
They are mcde_sys_wifi_config_ok in net.c now (one implementation for the file
that is built on every system), the NetBSD branch calls it, and the new
test_netinput.c runs 46 checks as an ordinary user: name 1..32 bytes (33
refused), passphrase none or 8..63 (7 and 64 refused), a quote, a backslash or
a newline in either (also a whole injected "network={" block), the interface
name (lower case and digits only), plus the two helpers net.c already had
without a test: mcde_sys_net_ifname_ok and mcde_sys_net_prefix (a
non-contiguous netmask, trailing text).
One behaviour change, found by writing the table: an EMPTY interface name
passed the inline check (strspn("") == strlen("")) and would have given
wpa_supplicant_flags="-B -s -i -D bsd ..."; it is refused now.
Measured: make check 6 of 6. Mutation check: with the SSID limit raised to 33,
with the empty-name guard removed, with the passphrase minimum 7, and with the
quote check left out of the passphrase, test_netinput fails (1, 1, 1 and 2
cases); the real code passes. netbsd.c and net.c compile for NetBSD
(x86_64--netbsd-gcc) without a diagnostic. Not run on NetBSD.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
100 lines
4.0 KiB
C
100 lines
4.0 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));
|
|
|
|
/* 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;
|
|
}
|