diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2018-04-12 10:43:12 +0300 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2018-04-12 10:43:12 +0300 |
commit | e206c39bb6bf91808dbcd2cfbd572525825982cd (patch) | |
tree | 385b7472d0212dc14f83f7adb5173dc6bb711c59 | |
parent | 5d99256613ccbdf4dfe7ea5f01d11f0bc4775326 (diff) |
Cygwin: fix guard checking for current user's AuthZ context
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
-rw-r--r-- | winsup/cygwin/sec_helper.cc | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/winsup/cygwin/sec_helper.cc b/winsup/cygwin/sec_helper.cc index 347836064..a1d8cba05 100644 --- a/winsup/cygwin/sec_helper.cc +++ b/winsup/cygwin/sec_helper.cc @@ -821,12 +821,16 @@ authz_ctx::get_user_attribute (mode_t *attribute, PSECURITY_DESCRIPTOR psd, if (RtlEqualSid (user_sid, cygheap->user.sid ()) && !cygheap->user.issetuid ()) { + /* Avoid lock in default case. */ if (!user_ctx_hdl) { authz_guard.acquire (); - if (!AuthzInitializeContextFromToken (0, hProcToken, authz, NULL, - authz_dummy_luid, NULL, - &user_ctx_hdl)) + /* Check user_ctx_hdl again under lock to avoid overwriting + user_ctx_hdl if it has already been initialized. */ + if (!user_ctx_hdl + && !AuthzInitializeContextFromToken (0, hProcToken, authz, NULL, + authz_dummy_luid, NULL, + &user_ctx_hdl)) debug_printf ("AuthzInitializeContextFromToken, %E"); authz_guard.release (); } |