]> ruderich.org/simon Gitweb - coloredstderr/coloredstderr.git/blobdiff - src/coloredstderr.c
Prevent crash in execve() if env is NULL
[coloredstderr/coloredstderr.git] / src / coloredstderr.c
index f1f2599927eb99130947afdd4f272ef86f9b305a..9161fc34f3deff694dba52eb07923fdde19bc4c2 100644 (file)
@@ -2,7 +2,7 @@
  * Hook output functions (like printf(3)) with LD_PRELOAD to color stderr (or
  * other file descriptors).
  *
- * Copyright (C) 2013-2015  Simon Ruderich
+ * Copyright (C) 2013-2018  Simon Ruderich
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -554,6 +554,11 @@ pid_t vfork(void) {
 HOOK_FUNC_DEF3(int, execve, char const *, filename, char * const *, argv, char * const *, env) {
     DLSYM_FUNCTION(real_execve, "execve");
 
+    char * const fake_env[] = {NULL};
+    if (env == NULL) {
+        env = fake_env;
+    }
+
     /* Count environment variables. */
     size_t count = 0;
     char * const *x = env;