4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-18 04:19:21 +08:00

Add length check creating domain\group strings

Fix Coverity CID 153932

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2016-11-24 10:40:14 +01:00
parent 9fbd510569
commit 40668dcc7c

View File

@ -342,9 +342,9 @@ static bool
get_user_groups (WCHAR *logonserver, cygsidlist &grp_list,
PWCHAR user, PWCHAR domain)
{
WCHAR dgroup[MAX_DOMAIN_NAME_LEN + GNLEN + 2];
WCHAR dgroup[MAX_DOMAIN_NAME_LEN + GNLEN + 2], *grp_p;
LPGROUP_USERS_INFO_0 buf;
DWORD cnt, tot, len;
DWORD cnt, tot;
NET_API_STATUS ret;
/* Look only on logonserver */
@ -363,9 +363,8 @@ get_user_groups (WCHAR *logonserver, cygsidlist &grp_list,
return ret == NERR_UserNotFound || ret == ERROR_ACCESS_DENIED;
}
len = wcslen (domain);
wcscpy (dgroup, domain);
dgroup[len++] = L'\\';
grp_p = wcpncpy (dgroup, domain, MAX_DOMAIN_NAME_LEN);
*grp_p++ = L'\\';
for (DWORD i = 0; i < cnt; ++i)
{
@ -375,7 +374,8 @@ get_user_groups (WCHAR *logonserver, cygsidlist &grp_list,
DWORD dlen = sizeof (dom);
SID_NAME_USE use = SidTypeInvalid;
wcscpy (dgroup + len, buf[i].grui0_name);
*wcpncpy (grp_p, buf[i].grui0_name, sizeof dgroup / sizeof *dgroup
- (grp_p - dgroup) - 1) = L'\0';
if (!LookupAccountNameW (NULL, dgroup, gsid, &glen, dom, &dlen, &use))
debug_printf ("LookupAccountName(%W), %E", dgroup);
else if (well_known_sid_type (use))