X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fenv%2F__libc_start_main.c;h=10e559096a703202070da2eb95157487f588b937;hb=5cc187215681c2fc1563ad5136c389249aa3f70e;hp=ac37492298520cea05a4fcdcd7cd513dd91aa885;hpb=7e8b0761e57266f40b8d51105b84c50e504e89c5;p=musl diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c index ac374922..10e55909 100644 --- a/src/env/__libc_start_main.c +++ b/src/env/__libc_start_main.c @@ -1,8 +1,12 @@ #include +#include +#include +#include +#include "syscall.h" +#include "atomic.h" #include "libc.h" void __init_tls(size_t *); -void __init_security(size_t *); #ifndef SHARED static void dummy() {} @@ -11,11 +15,17 @@ extern void (*const __init_array_start)() __attribute__((weak)); extern void (*const __init_array_end)() __attribute__((weak)); #endif +static void dummy1(void *p) {} +weak_alias(dummy1, __init_ssp); + #define AUX_CNT 38 extern size_t __hwcap, __sysinfo; extern char *__progname, *__progname_full; +#ifndef SHARED +static +#endif void __init_libc(char **envp, char *pn) { size_t i, *auxv, aux[AUX_CNT] = { 0 }; @@ -33,7 +43,21 @@ void __init_libc(char **envp, char *pn) } __init_tls(aux); - __init_security(aux); + __init_ssp((void *)aux[AT_RANDOM]); + + if (aux[AT_UID]==aux[AT_EUID] && aux[AT_GID]==aux[AT_EGID] + && !aux[AT_SECURE]) return; + + struct pollfd pfd[3] = { {.fd=0}, {.fd=1}, {.fd=2} }; +#ifdef SYS_poll + __syscall(SYS_poll, pfd, 3, 0); +#else + __syscall(SYS_ppoll, pfd, 3, &(struct timespec){0}, 0, _NSIG/8); +#endif + for (i=0; i<3; i++) if (pfd[i].revents&POLLNVAL) + if (__sys_open("/dev/null", O_RDWR)<0) + a_crash(); + libc.secure = 1; } int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv) @@ -48,7 +72,7 @@ int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv) (*(void (**)())a)(); #endif - /* Pass control to to application */ + /* Pass control to the application */ exit(main(argc, argv, envp)); return 0; }