Codebase list libgpg-error / b26a227
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
2 changed file(s) with 15 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
299299
300300
301301 /* 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. */
303307 static FILE *trace_fp;
304308 static int trace_save_errno;
305309 static int trace_with_errno;
238238 CloseHandle (ctx->have_space_ev);
239239 CloseHandle (ctx->thread_hd);
240240 DeleteCriticalSection (&ctx->mutex);
241 _gpgrt_free (ctx);
241 free (ctx); /* Standard free! See comment in create_reader. */
242242
243243 return 0;
244244 }
255255 sec_attr.nLength = sizeof sec_attr;
256256 sec_attr.bInheritHandle = FALSE;
257257
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. */
258265 ctx = calloc (1, sizeof *ctx);
259266 if (!ctx)
260267 {
541548 CloseHandle (ctx->thread_hd);
542549 DeleteCriticalSection (&ctx->mutex);
543550 trace (("%p: writer is destroyed", ctx));
544 _gpgrt_free (ctx);
551 free (ctx); /* Standard free! See comment in create_writer. */
545552
546553 return 0;
547554 }
558565 sec_attr.nLength = sizeof sec_attr;
559566 sec_attr.bInheritHandle = FALSE;
560567
568 /* See comment at create_reader. */
561569 ctx = calloc (1, sizeof *ctx);
562570 if (!ctx)
563571 {