dhclient - Delete trailing NUL's when parsing NVT ASCII options.
authorAntonio Huete Jimenez <tuxillo@quantumachine.net>
Tue, 14 Aug 2012 22:54:02 +0000 (00:54 +0200)
committerAntonio Huete Jimenez <tuxillo@quantumachine.net>
Sun, 19 Aug 2012 14:30:57 +0000 (16:30 +0200)
- RFC 2132 says "Options containing NVT ASCII data SHOULD NOT include
  a trailing NULL; however, the receiver of such options MUST be
  prepared to delete trailing nulls if they exist."
- Should fix odd results when 'append'ing info to such options via
  dhclient.conf.

Taken-from: OpenBSD

sbin/dhclient/options.c

index 3db0db2..3022dd0 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: src/sbin/dhclient/options.c,v 1.39 2011/05/11 14:38:36 krw Exp $      */
+/*     $OpenBSD: src/sbin/dhclient/options.c,v 1.40 2012/06/26 14:36:11 krw Exp $      */
 
 /* DHCP options parsing and reassembly. */
 
 
 /* DHCP options parsing and reassembly. */
 
@@ -86,6 +86,19 @@ parse_option_buffer(struct option_data *options, unsigned char *buffer,
                        warning("rejecting bogus offer.");
                        return (0);
                }
                        warning("rejecting bogus offer.");
                        return (0);
                }
+
+               /*
+                * Strip trailing NULs from ascii ('t') options. They
+                * will be treated as DHO_PAD options. i.e. ignored. RFC 2132
+                * says "Options containing NVT ASCII data SHOULD NOT include
+                * a trailing NULL; however, the receiver of such options
+                * MUST be prepared to delete trailing nulls if they exist."
+                */
+               if (dhcp_options[code].format[0] == 't') {
+                       for (len = s[1]; len > 0 && s[len + 1] == '\0'; len--)
+                               ;
+               }
+
                /*
                 * If we haven't seen this option before, just make
                 * space for it and copy it there.
                /*
                 * If we haven't seen this option before, just make
                 * space for it and copy it there.