mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-07 04:00:32 +01:00
keyfile: fix integer list SSID parsing after 30c41a4b80
The regex was capturing integers larger than 3 digits, which aren't valid SSID integer list items because each byte of the SSID cannot be larger than 255. Add an explicit testcase for intlist SSIDs too. The previous regex was causing a testcase failure with an SSID of '1337' which it was interpreting as a single element intlist, but should have been interpreted as a string since it's clear > 255.
This commit is contained in:
parent
5fb8efbb19
commit
9cdc5021ab
4 changed files with 141 additions and 1 deletions
|
|
@ -749,7 +749,7 @@ get_uchar_array (GKeyFile *keyfile,
|
|||
gboolean new_format = FALSE;
|
||||
GRegex *regex;
|
||||
GMatchInfo *match_info;
|
||||
const char *pattern = "^[[:space:]]*[[:digit:]]+[[:space:]]*(;[[:space:]]*[[:digit:]]+[[:space:]]*)*(;[[:space:]]*)?$";
|
||||
const char *pattern = "^[[:space:]]*[[:digit:]]{1,3}[[:space:]]*(;[[:space:]]*[[:digit:]]{1,3}[[:space:]]*)*(;[[:space:]]*)?$";
|
||||
|
||||
regex = g_regex_new (pattern, 0, 0, NULL);
|
||||
g_regex_match (regex, tmp_string, 0, &match_info);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ KEYFILES = \
|
|||
ATT_Data_Connect_BT \
|
||||
ATT_Data_Connect_Plain \
|
||||
Test_String_SSID \
|
||||
Test_Intlist_SSID \
|
||||
Test_Wired_TLS_Old \
|
||||
Test_Wired_TLS_New \
|
||||
Test_Wired_TLS_Blob \
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
[connection]
|
||||
id=Test
|
||||
uuid=2f962388-e5f3-45af-a62c-ac220b8f7baa
|
||||
type=802-11-wireless
|
||||
|
||||
[802-11-wireless]
|
||||
ssid=98;108;97;104;49;50;51;52;
|
||||
|
||||
[ipv4]
|
||||
method=auto
|
||||
|
||||
|
|
@ -1438,6 +1438,131 @@ test_write_string_ssid (void)
|
|||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
#define TEST_INTLIST_SSID_FILE TEST_KEYFILES_DIR"/Test_Intlist_SSID"
|
||||
|
||||
static void
|
||||
test_read_intlist_ssid (void)
|
||||
{
|
||||
NMConnection *connection;
|
||||
NMSettingWireless *s_wifi;
|
||||
GError *error = NULL;
|
||||
gboolean success;
|
||||
const GByteArray *array;
|
||||
const char *expected_ssid = "blah1234";
|
||||
|
||||
connection = nm_keyfile_plugin_connection_from_file (TEST_INTLIST_SSID_FILE, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (connection);
|
||||
|
||||
success = nm_connection_verify (connection, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (success);
|
||||
|
||||
/* SSID */
|
||||
s_wifi = nm_connection_get_setting_wireless (connection);
|
||||
g_assert (s_wifi);
|
||||
|
||||
array = nm_setting_wireless_get_ssid (s_wifi);
|
||||
g_assert (array != NULL);
|
||||
g_assert_cmpint (array->len, ==, strlen (expected_ssid));
|
||||
g_assert_cmpint (memcmp (array->data, expected_ssid, strlen (expected_ssid)), ==, 0);
|
||||
|
||||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
static void
|
||||
test_write_intlist_ssid (void)
|
||||
{
|
||||
NMConnection *connection;
|
||||
NMSettingConnection *s_con;
|
||||
NMSettingWireless *s_wifi;
|
||||
NMSettingIP4Config *s_ip4;
|
||||
char *uuid, *testfile = NULL;
|
||||
GByteArray *ssid;
|
||||
unsigned char tmpssid[] = { 65, 49, 50, 51, 0, 50, 50 };
|
||||
gboolean success;
|
||||
NMConnection *reread;
|
||||
GError *error = NULL;
|
||||
pid_t owner_grp;
|
||||
uid_t owner_uid;
|
||||
GKeyFile *keyfile;
|
||||
gint *intlist;
|
||||
gsize len = 0, i;
|
||||
|
||||
connection = nm_connection_new ();
|
||||
g_assert (connection);
|
||||
|
||||
/* Connection setting */
|
||||
|
||||
s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
|
||||
g_assert (s_con);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_con));
|
||||
|
||||
uuid = nm_utils_uuid_generate ();
|
||||
g_object_set (s_con,
|
||||
NM_SETTING_CONNECTION_ID, "Intlist SSID Test",
|
||||
NM_SETTING_CONNECTION_UUID, uuid,
|
||||
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME,
|
||||
NULL);
|
||||
g_free (uuid);
|
||||
|
||||
/* Wireless setting */
|
||||
s_wifi = NM_SETTING_WIRELESS (nm_setting_wireless_new ());
|
||||
g_assert (s_wifi);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_wifi));
|
||||
|
||||
ssid = g_byte_array_sized_new (sizeof (tmpssid));
|
||||
g_byte_array_append (ssid, &tmpssid[0], sizeof (tmpssid));
|
||||
g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NULL);
|
||||
g_byte_array_free (ssid, TRUE);
|
||||
|
||||
/* IP4 setting */
|
||||
s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
|
||||
g_assert (s_ip4);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
|
||||
g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
|
||||
|
||||
/* Write out the connection */
|
||||
owner_uid = geteuid ();
|
||||
owner_grp = getegid ();
|
||||
success = nm_keyfile_plugin_write_test_connection (connection, TEST_SCRATCH_DIR, owner_uid, owner_grp, &testfile, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (success);
|
||||
g_assert (testfile != NULL);
|
||||
|
||||
/* Ensure the SSID was written out as an int list */
|
||||
keyfile = g_key_file_new ();
|
||||
success = g_key_file_load_from_file (keyfile, testfile, 0, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (success);
|
||||
|
||||
intlist = g_key_file_get_integer_list (keyfile, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID, &len, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (intlist);
|
||||
g_assert_cmpint (len, ==, sizeof (tmpssid));
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
g_assert_cmpint (intlist[i], ==, tmpssid[i]);
|
||||
g_free (intlist);
|
||||
|
||||
g_key_file_free (keyfile);
|
||||
|
||||
/* Read the connection back in and compare it to the one we just wrote out */
|
||||
reread = nm_keyfile_plugin_connection_from_file (testfile, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (reread);
|
||||
|
||||
success = nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT);
|
||||
g_assert (success);
|
||||
|
||||
g_clear_error (&error);
|
||||
unlink (testfile);
|
||||
g_free (testfile);
|
||||
|
||||
g_object_unref (reread);
|
||||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
#define TEST_BT_DUN_FILE TEST_KEYFILES_DIR"/ATT_Data_Connect_BT"
|
||||
|
||||
static void
|
||||
|
|
@ -2488,6 +2613,9 @@ int main (int argc, char **argv)
|
|||
test_read_string_ssid ();
|
||||
test_write_string_ssid ();
|
||||
|
||||
test_read_intlist_ssid ();
|
||||
test_write_intlist_ssid ();
|
||||
|
||||
test_read_bt_dun_connection ();
|
||||
test_write_bt_dun_connection ();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue