core,w32: Avoid recursive use of npth_unprotect.
* src/w32-estream.c (reader): Use standard free.
(writer): Ditto.
--
There are two errors: The minor one is that we allocated with calloc
but released with _gpgrt_free. The major one is the recursive use of
npth_unprotect due to the syscall_clamp mechanism:
1. Around the call to _gpgrt_w32_poll
2. By gpgrt_lock_lock on behalf of a the custom allocation handler in
the worker threads at their _gpgrt_free.
This problem was exhibited by GnuPG's dirmngr component.
GnuPG-bug-id: 3937
Signed-off-by: Werner Koch <wk@gnupg.org>
Werner Koch
6 years ago
299 | 299 |
|
300 | 300 |
|
301 | 301 |
/* Internal tracing functions. Except for TRACE_FP we use flockfile
|
302 | |
* and funlockfile to protect their use. */
|
|
302 |
* and funlockfile to protect their use.
|
|
303 |
*
|
|
304 |
* Warning: Take care with the trace functions - they may not use any
|
|
305 |
* of our services, in particular not the syscall clamp mechanism for
|
|
306 |
* reasons explained in w32-stream.c:create_reader. */
|
303 | 307 |
static FILE *trace_fp;
|
304 | 308 |
static int trace_save_errno;
|
305 | 309 |
static int trace_with_errno;
|
238 | 238 |
CloseHandle (ctx->have_space_ev);
|
239 | 239 |
CloseHandle (ctx->thread_hd);
|
240 | 240 |
DeleteCriticalSection (&ctx->mutex);
|
241 | |
_gpgrt_free (ctx);
|
|
241 |
free (ctx); /* Standard free! See comment in create_reader. */
|
242 | 242 |
|
243 | 243 |
return 0;
|
244 | 244 |
}
|
|
255 | 255 |
sec_attr.nLength = sizeof sec_attr;
|
256 | 256 |
sec_attr.bInheritHandle = FALSE;
|
257 | 257 |
|
|
258 |
/* The CTX must be allocated in standard system memory so that we
|
|
259 |
* won't use any custom allocation handler which may use our lock
|
|
260 |
* primitives for its implementation. The problem here is that the
|
|
261 |
* syscall clamp mechanism (e.g. nPth) would be called recursively:
|
|
262 |
* 1. For example by the caller of _gpgrt_w32_poll and 2. by
|
|
263 |
* gpgrt_lock_lock on behalf of the the custom allocation and free
|
|
264 |
* functions. */
|
258 | 265 |
ctx = calloc (1, sizeof *ctx);
|
259 | 266 |
if (!ctx)
|
260 | 267 |
{
|
|
541 | 548 |
CloseHandle (ctx->thread_hd);
|
542 | 549 |
DeleteCriticalSection (&ctx->mutex);
|
543 | 550 |
trace (("%p: writer is destroyed", ctx));
|
544 | |
_gpgrt_free (ctx);
|
|
551 |
free (ctx); /* Standard free! See comment in create_writer. */
|
545 | 552 |
|
546 | 553 |
return 0;
|
547 | 554 |
}
|
|
558 | 565 |
sec_attr.nLength = sizeof sec_attr;
|
559 | 566 |
sec_attr.bInheritHandle = FALSE;
|
560 | 567 |
|
|
568 |
/* See comment at create_reader. */
|
561 | 569 |
ctx = calloc (1, sizeof *ctx);
|
562 | 570 |
if (!ctx)
|
563 | 571 |
{
|