From 81a25ba7a420df67013b320b71f3548a32e50360 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 13 Jan 2025 12:05:02 +0100 Subject: [PATCH] altsvc: return error on dot-only name Because it is a trailing dot that otherwise leads to a zero length name. Coverity CID 1638755. Closes #15986 --- lib/altsvc.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/altsvc.c b/lib/altsvc.c index 62f2c545fe..a77b1cf279 100644 --- a/lib/altsvc.c +++ b/lib/altsvc.c @@ -108,19 +108,20 @@ static struct altsvc *altsvc_createid(const char *srchost, return NULL; DEBUGASSERT(hlen); DEBUGASSERT(dlen); - if(!hlen || !dlen) { + if(!hlen || !dlen) /* bad input */ - free(as); - return NULL; - } + goto error; if((hlen > 2) && srchost[0] == '[') { /* IPv6 address, strip off brackets */ srchost++; hlen -= 2; } - else if(srchost[hlen - 1] == '.') + else if(srchost[hlen - 1] == '.') { /* strip off trailing dot */ hlen--; + if(!hlen) + goto error; + } if((dlen > 2) && dsthost[0] == '[') { /* IPv6 address, strip off brackets */ dsthost++; -- 2.47.3