blob: 8d0922ed854635e852546b400f21d7194a5f6650 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
/* Make sure programs that override malloc don't mess us up:
*
* libsandbox's __attribute__((constructor)) libsb_init ->
* libsandbox's malloc() ->
* dlsym("mmap") ->
* glibc's libdl calls malloc ->
* tcmalloc's internal code calls open ->
* libsandbox's open wrapper is hit ->
* libsandbox tries to initialize itself (since it never finished originally) ->
* libsandbox's malloc() ->
* dlsym() -> deadlock
* https://crbug.com/586444
*/
#include "headers.h"
static void *malloc_hook(size_t size, const void *caller)
{
int urandom_fd = open("/dev/urandom", O_RDONLY);
close(urandom_fd);
return NULL;
}
void *(*__malloc_hook)(size_t, const void *) = &malloc_hook;
static void *thread_start(void *arg)
{
return arg;
}
int main(int argc, char *argv[])
{
/* Make sure we reference some pthread symbols, although we don't
* really want to execute it -- our malloc is limited. */
if (argc < 0) {
pthread_t tid;
pthread_create(&tid, NULL, thread_start, NULL);
}
/* Trigger malloc! */
if (malloc(100)) {}
return 0;
}
|