public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: posix timers: allocate timer_tracker on system heap.
Date: Tue, 22 Jan 2019 15:38:00 -0000	[thread overview]
Message-ID: <20190122153840.66238.qmail@sourceware.org> (raw)

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

commit 83c51fffe6bad36a7143c30946ac5445f9ca4c56
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Tue Jan 22 16:22:45 2019 +0100

    Cygwin: posix timers: allocate timer_tracker on system heap.
    
    Allocating on the cygheap would copy information of the tracker into
    the child process.  A forked child knows the timer id and could simply
    still access the (free'd but still valid) timer_tracker on the heap,
    which is dangerous and very certainly doesn't reflect POSIX semantics.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/cygheap_malloc.h | 3 +--
 winsup/cygwin/posix_timer.cc   | 5 +++--
 winsup/cygwin/posix_timer.h    | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/winsup/cygwin/cygheap_malloc.h b/winsup/cygwin/cygheap_malloc.h
index cd545c3..74f0bb6 100644
--- a/winsup/cygwin/cygheap_malloc.h
+++ b/winsup/cygwin/cygheap_malloc.h
@@ -34,8 +34,7 @@ enum cygheap_types
   HEAP_2_DLL,
   HEAP_MMAP,
   HEAP_2_MAX = 200,
-  HEAP_3_FHANDLER,
-  HEAP_3_TIMER
+  HEAP_3_FHANDLER
 };
 
 extern "C" {
diff --git a/winsup/cygwin/posix_timer.cc b/winsup/cygwin/posix_timer.cc
index 8651c22..e969dcc 100644
--- a/winsup/cygwin/posix_timer.cc
+++ b/winsup/cygwin/posix_timer.cc
@@ -414,10 +414,11 @@ timer_tracker::settime (int flags, const itimerspec *new_value,
   return ret;
 }
 
-/* The timers are stored on the cygheap. */
+/* The timers are stored on the system heap in order to avoid accidental
+   leaking of timer ids into the child process. */
 #define cnew(name, ...) \
   ({ \
-    void* ptr = (void*) ccalloc (HEAP_3_TIMER, 1, sizeof (name)); \
+    void* ptr = (void*) HeapAlloc (GetProcessHeap (), 0, sizeof (name)); \
     ptr ? new (ptr) name (__VA_ARGS__) : NULL; \
   })
 
diff --git a/winsup/cygwin/posix_timer.h b/winsup/cygwin/posix_timer.h
index 04a383f..f69a179 100644
--- a/winsup/cygwin/posix_timer.h
+++ b/winsup/cygwin/posix_timer.h
@@ -30,7 +30,7 @@ class timer_tracker
 
  public:
   void *operator new (size_t, void *p) __attribute__ ((nothrow)) {return p;}
-  void operator delete (void *p) { cfree (p); }
+  void operator delete (void *p) { HeapFree (GetProcessHeap (), 0, p); }
   timer_tracker (clockid_t, const sigevent *);
   ~timer_tracker ();
   inline bool is_timer_tracker () const { return magic == TT_MAGIC; }


                 reply	other threads:[~2019-01-22 15:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190122153840.66238.qmail@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).