In unix_parse(), always allocate memory for the entire struct sockaddr_un

and not just the part used by the present pathname, because the entire
struct will be passed to bind() and an EFAULT can result if not all of
it is a valid allocation.  Fixes PR kern/56533.
This commit is contained in:
gson 2021-12-07 10:39:33 +00:00
parent 7fb539076d
commit 8774b772cf
1 changed files with 3 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: sp_common.c,v 1.42 2020/06/13 16:51:59 kamil Exp $ */
/* $NetBSD: sp_common.c,v 1.43 2021/12/07 10:39:33 gson Exp $ */
/*
* Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved.
@ -670,12 +670,10 @@ unix_parse(const char *addr, struct sockaddr **sa, int allow_wildcard)
}
}
strcat(s_un.sun_path, addr);
#if defined(__linux__) || defined(__sun__) || defined(__CYGWIN__)
slen = sizeof(s_un);
#else
#if !(defined(__linux__) || defined(__sun__) || defined(__CYGWIN__))
s_un.sun_len = SUN_LEN(&s_un);
slen = s_un.sun_len+1; /* get the 0 too */
#endif
slen = sizeof(s_un);
if (savepath && *parsedurl == '\0') {
snprintf(parsedurl, sizeof(parsedurl),