[newlib-cygwin] flock.cc: Fix stack allocation from callee used in caller

Corinna Vinschen corinna@sourceware.org
Tue Sep 8 14:40:00 GMT 2015


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=44e0f5a7036ef0d40a46d01d868e6db62d1a8cbb

commit 44e0f5a7036ef0d40a46d01d868e6db62d1a8cbb
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Tue Sep 8 10:57:54 2015 +0200

    flock.cc: Fix stack allocation from callee used in caller
    
    	* flock.cc (lockf_t::create_lock_obj_attr): Add buffer parameter.
    	Call _everyone_sd with buffer argument from caller rather than
    	everyone_sd with locally allocated stack buffer.
    	(lockf_t::create_lock_obj): Call create_lock_obj_attr only once
    	outside the loop and with additional buffer argument.
    	(lockf_t::open_lock_obj): Call create_lock_obj_attr with additional
    	buffer argument.

Diff:
---
 winsup/cygwin/ChangeLog | 10 ++++++++++
 winsup/cygwin/flock.cc  | 14 ++++++++------
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index d9ab975..2c59cd9 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,13 @@
+2015-09-08  Corinna Vinschen  <corinna@vinschen.de>
+
+	* flock.cc (lockf_t::create_lock_obj_attr): Add buffer parameter.
+	Call _everyone_sd with buffer argument from caller rather than
+	everyone_sd with locally allocated stack buffer.
+	(lockf_t::create_lock_obj): Call create_lock_obj_attr only once
+	outside the loop and with additional buffer argument.
+	(lockf_t::open_lock_obj): Call create_lock_obj_attr with additional
+	buffer argument.
+
 2015-08-29  Corinna Vinschen  <corinna@vinschen.de>
 
 	* fhandler_proc.cc (format_proc_cpuinfo): Fetch cache information
diff --git a/winsup/cygwin/flock.cc b/winsup/cygwin/flock.cc
index 2332f54..f26a76a 100644
--- a/winsup/cygwin/flock.cc
+++ b/winsup/cygwin/flock.cc
@@ -290,7 +290,7 @@ class lockf_t
     { cfree (p); }
 
     POBJECT_ATTRIBUTES create_lock_obj_attr (lockfattr_t *attr,
-					     ULONG flags);
+					     ULONG flags, void *sd_buf);
 
     void create_lock_obj ();
     bool open_lock_obj ();
@@ -636,7 +636,7 @@ inode_t::get_all_locks_list ()
 /* Create the lock object name.  The name is constructed from the lock
    properties which identify it uniquely, all values in hex. */
 POBJECT_ATTRIBUTES
-lockf_t::create_lock_obj_attr (lockfattr_t *attr, ULONG flags)
+lockf_t::create_lock_obj_attr (lockfattr_t *attr, ULONG flags, void *sd_buf)
 {
   __small_swprintf (attr->name, LOCK_OBJ_NAME_FMT,
 		    lf_flags & (F_POSIX | F_FLOCK), lf_type, lf_start, lf_end,
@@ -644,7 +644,7 @@ lockf_t::create_lock_obj_attr (lockfattr_t *attr, ULONG flags)
   RtlInitCountedUnicodeString (&attr->uname, attr->name,
 			       LOCK_OBJ_NAME_LEN * sizeof (WCHAR));
   InitializeObjectAttributes (&attr->attr, &attr->uname, flags, lf_inode->i_dir,
-			      everyone_sd (FLOCK_EVENT_ACCESS));
+			      _everyone_sd (sd_buf, FLOCK_EVENT_ACCESS));
   return &attr->attr;
 }
 
@@ -766,11 +766,13 @@ lockf_t::create_lock_obj ()
 {
   lockfattr_t attr;
   NTSTATUS status;
+  POBJECT_ATTRIBUTES lock_obj_attr;
 
+  lock_obj_attr = create_lock_obj_attr (&attr, OBJ_INHERIT,
+					alloca (SD_MIN_SIZE));
   do
     {
-      status = NtCreateEvent (&lf_obj, CYG_EVENT_ACCESS,
-			      create_lock_obj_attr (&attr, OBJ_INHERIT),
+      status = NtCreateEvent (&lf_obj, CYG_EVENT_ACCESS, lock_obj_attr,
 			      NotificationEvent, FALSE);
       if (!NT_SUCCESS (status))
 	{
@@ -852,7 +854,7 @@ lockf_t::open_lock_obj ()
   NTSTATUS status;
 
   status = NtOpenEvent (&lf_obj, FLOCK_EVENT_ACCESS,
-			create_lock_obj_attr (&attr, 0));
+			create_lock_obj_attr (&attr, 0, alloca (SD_MIN_SIZE)));
   if (!NT_SUCCESS (status))
     {
       SetLastError (RtlNtStatusToDosError (status));



More information about the Cygwin-cvs mailing list