dumpleases: make host names sanitized to shell-friendly condition
authorDenys Vlasenko <vda.linux@googlemail.com>
Sat, 24 Oct 2015 02:45:22 +0000 (04:45 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sat, 24 Oct 2015 02:45:22 +0000 (04:45 +0200)
function                                             old     new   delta
add_lease                                            271     298     +27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
networking/udhcp/leases.c

index 745340ad3a60fa5b53a8a2d4daa536f4bd392050..844bb60b17f77558300c9baa9747dd5412e92f8d 100644 (file)
@@ -65,10 +65,15 @@ struct dyn_lease* FAST_FUNC add_lease(
                        if (hostname_len > sizeof(oldest->hostname))
                                hostname_len = sizeof(oldest->hostname);
                        p = safe_strncpy(oldest->hostname, hostname, hostname_len);
-                       /* sanitization (s/non-ASCII/^/g) */
+                       /*
+                        * Sanitization (s/bad_char/./g).
+                        * The intent is not to allow only "DNS-valid" hostnames,
+                        * but merely make dumpleases output safe for shells to use.
+                        * We accept "0-9A-Za-z._-", all other chars turn to dots.
+                        */
                        while (*p) {
-                               if (*p < ' ' || *p > 126)
-                                       *p = '^';
+                               if (!isalnum(*p) && *p != '-' && *p != '_')
+                                       *p = '.';
                                p++;
                        }
                }