Don't relocate file descriptor memory

This change fixes #496 where ASAN spotted a race condition that could
happen in multithreaded programs, with more than OPEN_MAX descriptors
when using ZipOS or Windows NT, which require tracking open file info
and this change fixes that table so it never relocates, thus allowing
us to continue to enjoy the benefits of avoiding locks while reading.
This commit is contained in:
Justine Tunney 2022-09-09 16:54:28 -07:00
parent c3208eb9d5
commit 3265324e00
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
35 changed files with 297 additions and 152 deletions

View file

@ -24,6 +24,7 @@
*/
#include "libc/fmt/fmt.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "third_party/gdtoa/gdtoa.h"
@ -33,10 +34,24 @@ Copyright (c) 2002, 2006, 2010 Todd C. Miller <millert@openbsd.org>\"");
asm(".include \"libc/disclaimer.inc\"");
// clang-format off
static char *s;
static void
__cvt_atexit(void)
{
free(s);
s = 0;
}
static void __attribute__((__constructor__))
__cvt_init(void)
{
atexit(__cvt_atexit);
}
static char *
__cvt(double value, int ndigit, int *decpt, int *sign, int fmode, int pad)
{
static char *s;
char *p, *rve, c;
size_t siz;