This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 2808c2fa99d libs/libc/netdb: Reject empty labels in dn_comp().
2808c2fa99d is described below
commit 2808c2fa99d6903d170fa7d2014486c6ca342400
Author: Marco Casaroli <[email protected]>
AuthorDate: Sat Oct 17 20:25:44 2026 +0200
libs/libc/netdb: Reject empty labels in dn_comp().
dn_comp() must reject a domain name with an empty label, for example
"a..b" or ".a". The label length check in getlens() used a signed
difference, so an empty label gave -1 and passed the check. dn_comp()
then wrote a zero length byte in the middle of the name, and the
encoded name ended early.
This commit rejects a label with 0 bytes or more than 63 bytes.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
libs/libc/netdb/lib_dn.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/libs/libc/netdb/lib_dn.c b/libs/libc/netdb/lib_dn.c
index 6003c278816..20d61f95252 100644
--- a/libs/libc/netdb/lib_dn.c
+++ b/libs/libc/netdb/lib_dn.c
@@ -78,7 +78,10 @@ static int getlens(FAR unsigned char *lens, FAR const char
*s, int l)
for (; ; )
{
for (; j < l && s[j] != '.'; j++);
- if (j - k - 1 > 62)
+
+ /* A label has 1 to 63 bytes */
+
+ if (j == k || j - k > 63)
{
return 0;
}