summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2017-02-07 18:26:54 +0100
committerTobias Klauser <tklauser@distanz.ch>2017-02-07 18:26:54 +0100
commit371de55728931fc253763328ae322ce9512afba1 (patch)
tree070400e399c0dd45bf6d4cdfa1f1f1341c0e7c01
parent70ff9183e5533d6f0bfccf20bb67ac18d0bbb493 (diff)
llmnrd: compare full hostname in query, fix off-by-one error
When checking whether the hostname matches, llmnrd does not consider the last character of the hostnames, leading to the following incorrect behavior: $ ./llmnrd -H foobar Starting llmnrd on port 5355, hostname foobar ... $ ./llmnr-query foobaZ LLMNR query: foobaZ IN ANY LLMNR response: foobar IN A 10.42.0.42 (TTL 30) Fix it by considering the full hostname. Also do only convert alphabetic characters to lowercase using tolower(3), since its behavior is undefined for any other characters. Fixes #21 Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--llmnr.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/llmnr.c b/llmnr.c
index 64fcabd..0b35ae7 100644
--- a/llmnr.c
+++ b/llmnr.c
@@ -61,9 +61,15 @@ static bool llmnr_name_matches(const uint8_t *query)
if (query[1 + n] != 0)
return false;
- for (i = 1; i < llmnr_hostname[0]; i++)
- if (tolower(query[i]) != tolower(llmnr_hostname[i]))
+ for (i = 1; i <= n; i++) {
+ char a = query[i];
+ char b = llmnr_hostname[i];
+ a = isalpha(a) ? tolower(a) : a;
+ b = isalpha(b) ? tolower(b) : b;
+ if (a != b) {
return false;
+ }
+ }
return true;
}