dumpleases: make host names sanitized to shell-friendly condition

function                                             old     new   delta
add_lease                                            271     298     +27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2015-10-24 04:45:22 +02:00
parent 941e7a4919
commit 9a51217668

View File

@ -65,10 +65,15 @@ struct dyn_lease* FAST_FUNC add_lease(
if (hostname_len > sizeof(oldest->hostname)) if (hostname_len > sizeof(oldest->hostname))
hostname_len = sizeof(oldest->hostname); hostname_len = sizeof(oldest->hostname);
p = safe_strncpy(oldest->hostname, hostname, hostname_len); 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) { while (*p) {
if (*p < ' ' || *p > 126) if (!isalnum(*p) && *p != '-' && *p != '_')
*p = '^'; *p = '.';
p++; p++;
} }
} }