[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#818611: marked as done (netcfg: Misleading error message when parsing line with trailing blank)



Your message dated Sat, 02 Apr 2016 06:34:31 +0000
with message-id <E1amF8h-00012V-A0@franck.debian.org>
and subject line Bug#818611: fixed in netcfg 1.138
has caused the Debian Bug report #818611,
regarding netcfg: Misleading error message when parsing line with trailing blank
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@bugs.debian.org
immediately.)


-- 
818611: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=818611
Debian Bug Tracking System
Contact owner@bugs.debian.org with problems
--- Begin Message ---
Package: netcfg
Version: 1.137
Severity: normal
Tags: d-i

Dear maintainer(s),

when specifying IP addresses with leading or trailing blanks, netcfg does not
correctly identify the IP address and fails.  For example,

	Configure a network using static addressing  
	-------------------------------------------  
	  
	The IP address is unique to your computer and may be:  
	  
	 * four numbers separated by periods (IPv4);  
	 * blocks of hexadecimal characters separated by colons (IPv6).  
	  
	You can also optionally append a CIDR netmask (such as "/24").  
	  
	If you don't know what to use here, consult your network administrator.  
	IP address:  
	Prompt: '?' for help> 9.152.162.103
	9.152.162.103     
	  
	!! ERROR: Malformed IP address  
	  
	The IP address you provided is malformed. It should be in the form x.x.x.x   
	where each 'x' is no larger than 255 (an IPv4 address), or a sequence of blocks 
	 
	of hexadecimal digits separated by colons (an IPv6 address). Please try again.  
	Press enter to continue

This can easily happen, especially, when entering IP addresses within
command line console, such as the z/VM console on z Systems (s390x).

The expected behavior is that leading and trailing blanks should be ignored.
Note that the root cause of the error condition above is triggered by a
failing inet_pton() call which does not expect blanks for an IP address
string.

To correct this behavior, I have attached two patches for discussion:

The first patch removes trailing blanks for the case above. Note that there
is already an rtrim() function that has been reused.  Also an additional
function, strtrim(), is introduced to remove any leading blanks.
The "make test" has been enhanced to verify this behavior.

The second patch removes leading and trailing blanks on IP addresses entered
for other network configurations, for example, point-to-point.

Feedback is welcome.

Thanks and kind regards,
  Hendrik

-- 
Hendrik Brueckner
brueckner@linux.vnet.ibm.com      | IBM Deutschland Research & Development GmbH
Linux on z Systems Development    | Schoenaicher Str. 220, 71032 Boeblingen
>From 944acf2a089e5eb60a76c58d896f8c3713aad0a4 Mon Sep 17 00:00:00 2001
From: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
Date: Fri, 5 Feb 2016 16:32:42 +0100
Subject: [PATCH 1/2] common/ipaddr: remove leading and trailing whitespaces

Leading or trailing whitespaces are not removed from the IP address,
for example, when specified by the user.  If the IP address contains
whitespaces, parsing the address fails and a malformed address is
reported even if the IP address would be valid.

To remove trailing whitespaces, extend the rtrim() function to remove
multiple spaces.  Introduce a new function, strtrim() to remove any
leading spaces.

Also add a test case to verify the changed behavior.

Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
---
 netcfg-common.c                       | 24 +++++++++++++++++++++---
 netcfg.h                              |  1 +
 test/test_netcfg_parse_cidr_address.c | 26 ++++++++++++++++++++++++++
 3 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/netcfg-common.c b/netcfg-common.c
index 376e6ca..c6d1d8d 100644
--- a/netcfg-common.c
+++ b/netcfg-common.c
@@ -1577,10 +1577,11 @@ int netcfg_parse_cidr_address(const char *address, struct netcfg_interface *inte
     struct in_addr addr;
     struct in6_addr addr6;
     int ok;
-    char *maskptr, addrstr[NETCFG_ADDRSTRLEN];
+    char *maskptr, *addrstr, addrbuf[NETCFG_ADDRSTRLEN];
     int i;
     
-    strncpy(addrstr, address, NETCFG_ADDRSTRLEN);
+    strncpy(addrbuf, address, NETCFG_ADDRSTRLEN);
+    addrstr = strtrim(addrbuf);
     
     if ((maskptr = strchr(addrstr, '/'))) {
         /* Houston, we have a netmask; split it into bits */
@@ -1730,7 +1731,24 @@ void rtrim(char *s)
 	
 	n = strlen(s) - 1;
 	
-	while (isspace(s[n])) {
+	while (n >= 0 && isspace(s[n])) {
 		s[n] = '\0';
+		n--;
 	}
 }
+
+char *strtrim(char *s)
+{
+	size_t len;
+
+	len = strlen(s);
+	if (!len)
+		return s;
+
+	rtrim(s);
+
+	while (*s && isspace(*s))
+		s++;
+
+	return s;
+}
diff --git a/netcfg.h b/netcfg.h
index 771fed3..00a2cea 100644
--- a/netcfg.h
+++ b/netcfg.h
@@ -249,6 +249,7 @@ extern void preseed_hostname_from_fqdn(struct debconfclient *client, char *fqdn)
 extern int netcfg_dhcp(struct debconfclient *client, struct netcfg_interface *interface);
 
 extern void rtrim(char *);
+extern char *strtrim(char *s);
 
 /* ipv6.c */
 extern void nc_v6_wait_for_complete_configuration(const struct netcfg_interface *interface);
diff --git a/test/test_netcfg_parse_cidr_address.c b/test/test_netcfg_parse_cidr_address.c
index 8f0f919..2b1cdca 100644
--- a/test/test_netcfg_parse_cidr_address.c
+++ b/test/test_netcfg_parse_cidr_address.c
@@ -101,6 +101,31 @@ START_TEST(test_parse_cidr_v6_address)
 }
 END_TEST
 
+START_TEST(test_parse_cidr_ignore_leading_trailing_spaces)
+{
+	struct netcfg_interface interface;
+	netcfg_interface_init(&interface);
+	int rv;
+
+	interface.masklen = 7;
+	rv = netcfg_parse_cidr_address("   192.0.2.12   ", &interface);
+
+	fail_unless (rv,
+	             "parsing failed, rv = %i", rv);
+
+	fail_unless (interface.masklen == 0,
+	             "masklen was %i, should have been 0",
+	             interface.masklen);
+
+	fail_unless (strcmp("192.0.2.12", interface.ipaddress) == 0,
+	             "IP address was %s, should have been 192.10.2.12",
+	             interface.ipaddress);
+
+	fail_unless (interface.address_family == AF_INET,
+	             "Address family should have been AF_INET");
+}
+END_TEST
+
 Suite *test_netcfg_parse_cidr_address_suite (void)
 {
 	Suite *s = suite_create ("netcfg_parse_cidr_address");
@@ -110,6 +135,7 @@ Suite *test_netcfg_parse_cidr_address_suite (void)
 	tcase_add_test (tc, test_parse_cidr_v4_address);
 	tcase_add_test (tc, test_parse_standalone_v6_address);
 	tcase_add_test (tc, test_parse_cidr_v6_address);
+	tcase_add_test (tc, test_parse_cidr_ignore_leading_trailing_spaces);
 	
 	suite_add_tcase (s, tc);
 	
-- 
2.7.0

>From f14ecde4b8e70cddc1b55c0f2b942f0ce3c28e3e Mon Sep 17 00:00:00 2001
From: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
Date: Fri, 5 Feb 2016 17:04:39 +0100
Subject: [PATCH 2/2] static: trim user-specified values for IP and other
 addresses

Remove leading and trailing spaces for IP addresses specified by
the user.  The inet_pton() function fails to parse addresses if
spaces are present.

Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
---
 static.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/static.c b/static.c
index 608c11d..ea12fba 100644
--- a/static.c
+++ b/static.c
@@ -39,6 +39,7 @@ static int netcfg_get_pointopoint(struct debconfclient *client, struct netcfg_in
 {
     int ret, ok = 0;
     union inX_addr addr;
+    char *ptr;
     
     while (!ok) {
         debconf_input(client, "critical", "netcfg/get_pointopoint");
@@ -48,13 +49,14 @@ static int netcfg_get_pointopoint(struct debconfclient *client, struct netcfg_in
             return ret;
 
         debconf_get(client, "netcfg/get_pointopoint");
+        ptr = strtrim(client->value);
 
-        if (empty_str(client->value)) {           /* No P-P is ok */
+        if (empty_str(ptr)) {           /* No P-P is ok */
             interface->pointopoint[0] = '\0';
             return 0;
         }
 
-        ok = inet_pton (interface->address_family, client->value, &addr);
+        ok = inet_pton (interface->address_family, ptr, &addr);
 
         if (!ok) {
             debconf_capb(client);
@@ -72,12 +74,14 @@ static int netcfg_get_netmask(struct debconfclient *client, struct netcfg_interf
 {
     int ret, ok = 0;
     union inX_addr addr;
+    char *ptr;
 
     /* Preseed a vaguely sensible looking default netmask if one wasn't
      * provided.
      */
     debconf_get (client, "netcfg/get_netmask");
-    if (empty_str(client->value)) {
+    ptr = strtrim(client->value);
+    if (empty_str(ptr)) {
         if (interface->address_family == AF_INET) {
             debconf_set(client, "netcfg/get_netmask", "255.255.255.0");
         } else if (interface->address_family == AF_INET6) {
@@ -94,7 +98,8 @@ static int netcfg_get_netmask(struct debconfclient *client, struct netcfg_interf
 
         debconf_get (client, "netcfg/get_netmask");
 
-        ok = inet_pton (interface->address_family, client->value, &addr);
+        ptr = strtrim(client->value);
+        ok = inet_pton (interface->address_family, ptr, &addr);
 
         if (!ok) {
             debconf_capb(client);
@@ -104,7 +109,7 @@ static int netcfg_get_netmask(struct debconfclient *client, struct netcfg_interf
         }
     }
 
-    inet_ptom(interface->address_family, client->value, &(interface->masklen));
+    inet_ptom(interface->address_family, ptr, &(interface->masklen));
     return 0;
 }
 
@@ -163,7 +168,7 @@ static int netcfg_get_gateway(struct debconfclient *client, struct netcfg_interf
             return ret;
 
         debconf_get(client, "netcfg/get_gateway");
-        ptr = client->value;
+        ptr = strtrim(client->value);
 
         if (empty_str(ptr) || /* No gateway, that's fine */
             (strcmp(ptr, "none") == 0)) /* special case for preseeding */ {
-- 
2.7.0


--- End Message ---
--- Begin Message ---
Source: netcfg
Source-Version: 1.138

We believe that the bug you reported is fixed in the latest version of
netcfg, which is due to be installed in the Debian FTP archive.

A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 818611@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Christian Perrier <bubulle@debian.org> (supplier of updated netcfg package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@ftp-master.debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Format: 1.8
Date: Sat, 02 Apr 2016 08:06:37 +0200
Source: netcfg
Binary: netcfg netcfg-static
Architecture: source i386
Version: 1.138
Distribution: unstable
Urgency: medium
Maintainer: Debian Install System Team <debian-boot@lists.debian.org>
Changed-By: Christian Perrier <bubulle@debian.org>
Description:
 netcfg     - Configure the network (udeb)
 netcfg-static - Configure a static network (udeb)
Closes: 818611
Changes:
 netcfg (1.138) unstable; urgency=medium
 .
   [ Hendrik Brueckner ]
   * common/ipaddr: remove leading and trailing whitespaces
   * static: trim user-specified values for IP and other addresses
   * Closes: #818611, LP: #1541955
 .
   [ Dimitri John Ledkov ]
   * dhcp.c: check return result of two more fgets calls
   * nm-conf.c: check return result of fscanf
   * Makefile: link with -lm to resolve undefined log and other functions
   * All of above resolves FTBFS
Checksums-Sha1:
 777673aad426fce98d323b5777bcc3203e87fb64 1893 netcfg_1.138.dsc
 76a60d6c73e0fba45043456dc27ccb00fb70c898 392924 netcfg_1.138.tar.xz
 5a97b3b6c636e9c745d1c7d637b893aead533546 353392 netcfg-static_1.138_i386.udeb
 e3081057328c3d3e07012cfad9148f94473281bb 448040 netcfg_1.138_i386.udeb
Checksums-Sha256:
 afd87910c6c3c7e96ddafb7f4d93b17e9674f154381ad0055683835fe710e10e 1893 netcfg_1.138.dsc
 ea298072ff3d5e4814bdc750a4e44da61c5c719eab3501c92d073c44cc27289a 392924 netcfg_1.138.tar.xz
 723154038093b8724ca98bbdc2ca703e75994bb5afdcbe0259483756a36e714d 353392 netcfg-static_1.138_i386.udeb
 4c70d020e1318094b6932f9dbf4d458d40f88499f73b7697343b323e3d4b0d5e 448040 netcfg_1.138_i386.udeb
Files:
 c0955f31ea8cb2e8f8e47638f01bcc89 1893 debian-installer optional netcfg_1.138.dsc
 aa618d87b92f8bce19509e94d2d00e27 392924 debian-installer optional netcfg_1.138.tar.xz
 050bbe6c0ce9371b48ee68c9981562d2 353392 debian-installer optional netcfg-static_1.138_i386.udeb
 991ae52d9efed99f81c693fc85b7ce06 448040 debian-installer optional netcfg_1.138_i386.udeb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCAAGBQJW/2STAAoJEIcvcCxNbiWodcgQAK3DaBczmoPN27T0uEz+K9R6
8sb2ATB1JGPSII59vSziKXAu++U2Zd6a87XKy2k4Cr3iT4CKw/1ks5MhCViNDg4U
zCnyK7uv95AzuHtOPSvcwQyrO0VrFu10GBGxPXmoJEHS4UmajPoO39B94YVG/k0S
N6Kw00S7me02P9QF4RPDxCv43fxnzm//LrADUTJp1Ipbd6mJQ6M8wVD4LBrSppni
nrk35OcEU6oaNl+IJSJHYdCoIEmLulPlIwu1F6+dIT+dPy8HoWYkAcaqwHiuqApp
mVW8CVEgfAsAvotCP6RRNBT90qh5u1Up+XXBed7NrOsvDC0z/9L+2mJ3Ozvvn5bK
pif6CiV6CQR62WumNxkGiGgmYDYIvnQL8SjjM85Bz+piS+Pvc3pfuCxYfj++uKHC
CLgVe4Ch0tLCh+Y9ha4IWJFGEN/Ve6WZoJRWPcU5qv3wjjaaB6ByMRk9V+AAIe9b
92+/qcOp4GT5WqHe0xKLkzpabxjEBpLK+UYeh3Df1vtCHdricE3au3qVdtiy4l/b
uGRpOKlqn9fzTZziWmSBedUW0iAiJO0oqOuW25SsS0E6DajNSbT+wPGU0bjt3tqV
ZHVt1hWwcZEmXxjDzX63hc9WoOtLFJMozG4qtW/dYWcOA3OvvOAKIThA7O14Oo/z
QMVJjBi8X0zRTr3thC8X
=tcfT
-----END PGP SIGNATURE-----

--- End Message ---

Reply to: