jail: preload: avoid NULL-dereference in case things go wrong
[project/procd.git] / jail / preload.c
index a1cc0b69ebaaf45d9b0a7279c3c1ae747b0bb264..351a9f81368bfd563c83e1a0e06409385dbe99de 100644 (file)
 
 #define _GNU_SOURCE
 #include <sys/types.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
 #include <dlfcn.h>
-#include <syslog.h>
 
+#include "log.h"
 #include "seccomp.h"
 #include "../preload.h"
 
 static main_t __main__;
+int debug;
 
 static int __preload_main__(int argc, char **argv, char **envp)
 {
        char *env_file = getenv("SECCOMP_FILE");
+       char *env_debug = getenv("SECCOMP_DEBUG");
+
+       if (!env_file || !env_file[0]) {
+               ERROR("SECCOMP_FILE not specified\n");
+               return -1;
+       }
+
+       if (env_debug)
+               debug = atoi(env_debug);
+       else
+               debug = 0;
 
        if (install_syscall_filter(*argv, env_file))
                return -1;
 
        unsetenv("LD_PRELOAD");
+       unsetenv("SECCOMP_DEBUG");
        unsetenv("SECCOMP_FILE");
 
        return (*__main__)(argc, argv, envp);
@@ -50,8 +62,10 @@ int __libc_start_main(main_t main,
        start_main_t __start_main__;
 
        __start_main__ = dlsym(RTLD_NEXT, "__libc_start_main");
-       if (!__start_main__)
+       if (!__start_main__) {
                INFO("failed to find __libc_start_main %s\n", dlerror());
+               return -1;
+       }
 
        __main__ = main;
 
@@ -70,8 +84,10 @@ void __uClibc_main(main_t main,
        uClibc_main __start_main__;
 
        __start_main__ = dlsym(RTLD_NEXT, "__uClibc_main");
-       if (!__start_main__)
+       if (!__start_main__) {
                INFO("failed to find __uClibc_main %s\n", dlerror());
+               return;
+       }
 
        __main__ = main;