From f7ce8a4d9e4c94c8280aafdec09fd1c8c7714bef Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 15 Oct 2021 08:09:25 +0200 Subject: [PATCH] BUG/MEDIUM: resolvers: fix truncated TLD consecutive to the API fix A bug was introduced by commit previous bf9498a31 ("MINOR: resolvers: fix the resolv_str_to_dn_label() API about trailing zero") as the code is particularly contrived and hard to test. The output writes the last char at [i+1] so the trailing zero and return value must be at i+1. This will have to be backported where the patch above is backported since it was needed for a fix. (cherry picked from commit 7b232f132dc9a0a6ee6fa3fabfa6e50196af9240) Signed-off-by: Willy Tarreau (cherry picked from commit 68c7b36f637c5d9a05b32b2868e44ea838f83f78) Signed-off-by: Christopher Faulet --- src/dns.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dns.c b/src/dns.c index 2d84923..4090ef5 100644 --- a/src/dns.c +++ b/src/dns.c @@ -1752,8 +1752,8 @@ int dns_str_to_dn_label(const char *str, int str_len, char *dn, int dn_len) dn[i+1] = str[i]; } dn[offset] = (i - offset); - dn[i] = '\0'; - return i; + dn[i+1] = '\0'; + return i+1; } /* Validates host name: -- 1.7.10.4