summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2014-05-22 11:09:36 -0500
committerDan Williams <dcbw@redhat.com>2014-11-07 12:09:54 -0600
commit941897cc9721997d106e2ab7ac438dafe441fb4e (patch)
tree129f7a6d7084506f271dde71a940b1d3cfb36e33
parentb5668f22be6e8b2d3e93d84473e3f9d6d0117404 (diff)
downloadNetworkManager-941897cc9721997d106e2ab7ac438dafe441fb4e.tar.gz
ifcfg-rh: strip trailing whitespace from ifcfg files (rh #1100336)
shvar.c has apparently never stripped trailing whitespace, but obviously a shell doesn't care. Unfortunately NM does. Strip trailing whitespace before unescaping, to preserve quoted whitespace. https://bugzilla.redhat.com/show_bug.cgi?id=1100336
-rw-r--r--src/settings/plugins/ifcfg-rh/shvar.c3
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am3
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-trailing-spaces11
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c38
4 files changed, 53 insertions, 2 deletions
diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c
index 9a4d1d1e3a..bdfd40a31f 100644
--- a/src/settings/plugins/ifcfg-rh/shvar.c
+++ b/src/settings/plugins/ifcfg-rh/shvar.c
@@ -265,7 +265,8 @@ svGetValue (shvarFile *s, const char *key, gboolean verbatim)
for (s->current = s->lineList; s->current; s->current = s->current->next) {
line = s->current->data;
if (!strncmp (keyString, line, len)) {
- value = g_strdup (line + len);
+ /* Strip trailing spaces before unescaping to preserve spaces quoted whitespace */
+ value = g_strchomp (g_strdup (line + len));
if (!verbatim)
svUnescape (value);
break;
diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am b/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am
index 9c9a3b13f8..8941da3a62 100644
--- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am
+++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am
@@ -119,7 +119,8 @@ EXTRA_DIST = \
ifcfg-test-fcoe-vn2vn \
ifcfg-test-team-master \
ifcfg-test-team-port \
- ifcfg-test-team-port-empty-config
+ ifcfg-test-team-port-empty-config \
+ ifcfg-test-vlan-trailing-spaces
# make target dependencies can't have colons in their names, which ends up
# meaning that we can't add the alias files to EXTRA_DIST
diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-trailing-spaces b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-trailing-spaces
new file mode 100644
index 0000000000..4a31e475ae
--- /dev/null
+++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-trailing-spaces
@@ -0,0 +1,11 @@
+DEVICE="vlan201"
+ONBOOT=yes
+NETBOOT=yes
+BOOTPROTO=none
+IPADDR="10.130.70.7"
+NETMASK="255.255.0.0"
+TYPE=Vlan
+NAME="vlan201"
+VLAN=yes
+PHYSDEV="enccw0.0.fb00"
+
diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
index 9964254b71..fbb0b9686a 100644
--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
+++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
@@ -13452,6 +13452,43 @@ test_svUnescape (void)
g_rand_free (r);
}
+static void
+test_read_vlan_trailing_spaces (void)
+{
+ const char *testfile = TEST_IFCFG_DIR"/network-scripts/ifcfg-test-vlan-trailing-spaces";
+ NMConnection *connection;
+ gboolean success;
+ GError *error = NULL;
+ NMSettingVlan *s_vlan;
+ char *contents = NULL;
+
+ /* Ensure there is whitespace at the end of the VLAN interface name,
+ * to prevent the whitespace getting stripped off and committed mistakenly
+ * by something in the future.
+ */
+ success = g_file_get_contents (testfile, &contents, NULL, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+ g_assert (contents && contents[0]);
+ g_assert (strstr (contents, "DEVICE=\"vlan201\" \n"));
+ g_free (contents);
+
+ connection = connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL,
+ NULL, NULL, NULL, &error, NULL);
+ g_assert_no_error (error);
+ g_assert (connection != NULL);
+
+ s_vlan = nm_connection_get_setting_vlan (connection);
+ g_assert (s_vlan);
+
+ g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "vlan201");
+ g_assert_cmpstr (nm_setting_vlan_get_parent (s_vlan), ==, "enccw0.0.fb00");
+ g_assert_cmpint (nm_setting_vlan_get_id (s_vlan), ==, 201);
+ g_assert_cmpint (nm_setting_vlan_get_flags (s_vlan), ==, 0);
+
+ g_object_unref (connection);
+}
+
#define TEST_IFCFG_WIFI_OPEN_SSID_BAD_HEX TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-bad-hex"
#define TEST_IFCFG_WIFI_OPEN_SSID_LONG_QUOTED TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-long-quoted"
@@ -13477,6 +13514,7 @@ int main (int argc, char **argv)
nmtst_init_assert_logging (&argc, &argv);
g_test_add_func (TPATH "svUnescape", test_svUnescape);
+ g_test_add_func (TPATH "vlan-trailing-spaces", test_read_vlan_trailing_spaces);
g_test_add_func (TPATH "unmanaged", test_read_unmanaged);
g_test_add_func (TPATH "unmanaged-unrecognized", test_read_unmanaged_unrecognized);