From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 67148 invoked by alias); 1 Mar 2019 20:09:25 -0000 Mailing-List: contact cygwin-cvs-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cygwin-cvs-owner@cygwin.com Received: (qmail 67040 invoked by uid 9078); 1 Mar 2019 20:09:24 -0000 Date: Fri, 01 Mar 2019 20:09:00 -0000 Message-ID: <20190301200924.67038.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: load_user_profile: fix use-after-free issue X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: 6aef5a46d7f22841e6a859103bb3f8acea060b84 X-Git-Newrev: 7ba9d12a72a722e0f20a80716dbeaf293e66a714 X-SW-Source: 2019-q1/txt/msg00205.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=7ba9d12a72a722e0f20a80716dbeaf293e66a714 commit 7ba9d12a72a722e0f20a80716dbeaf293e66a714 Author: Corinna Vinschen Date: Fri Mar 1 21:04:02 2019 +0100 Cygwin: load_user_profile: fix use-after-free issue In case of a local machine account login, pi.lpProfilePath points to the buffer returned by NetUserGetInfo, but NetApiBufferFree is called prior to calling LoadUserProfileW. Fix by copying over usri3_profile to the local userpath buffer, just as in the AD case. Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/sec_auth.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/sec_auth.cc b/winsup/cygwin/sec_auth.cc index 0b5e112..077b37c 100644 --- a/winsup/cygwin/sec_auth.cc +++ b/winsup/cygwin/sec_auth.cc @@ -267,7 +267,11 @@ load_user_profile (HANDLE token, struct passwd *pw, cygpsid &usersid) else { if (ui->usri3_profile && *ui->usri3_profile) - pi.lpProfilePath = ui->usri3_profile; + { + wcsncpy (userpath, ui->usri3_profile, MAX_PATH - 1); + userpath[MAX_PATH - 1] = L'\0'; + pi.lpProfilePath = userpath; + } NetApiBufferFree (ui); } }