Skip to content

Commit 932b914

Browse files
pkillarjunac000
authored andcommitted
socket: Prevent buffer under-read in nxt_inet_addr()
This was found via ASan. Given a listener address like ":" (or any address where the first character is a colon) we can end up under-reading the addr->start buffer here if (nxt_slow_path(*(buf + length - 1) == '.')) { due to length (essentially the position of the ":" in the string) being 0. Seeing as any address that starts with a ":" is invalid Unit config wise, we should simply reject the address if length == 0 in nxt_sockaddr_inet_parse(). Link: <https://clang.llvm.org/docs/AddressSanitizer.html> Signed-off-by: Arjun <pkillarjun@protonmail.com> [ Commit message - Andrew ] Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
1 parent 7192076 commit 932b914

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/nxt_sockaddr.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,11 @@ nxt_sockaddr_inet_parse(nxt_mp_t *mp, nxt_str_t *addr)
732732
length = p - addr->start;
733733
}
734734

735+
if (length == 0) {
736+
nxt_thread_log_error(NXT_LOG_ERR, "invalid address \"%V\"", addr);
737+
return NULL;
738+
}
739+
735740
inaddr = INADDR_ANY;
736741

737742
if (length != 1 || addr->start[0] != '*') {

0 commit comments

Comments
 (0)