815a0e
diff -up cronie-1.4.11/src/security.c.ppp cronie-1.4.11/src/security.c
815a0e
--- cronie-1.4.11/src/security.c.ppp	2013-07-18 14:27:08.000000000 +0200
815a0e
+++ cronie-1.4.11/src/security.c	2013-08-30 14:00:15.263788467 +0200
815a0e
@@ -129,15 +129,13 @@ int cron_set_job_security_context(entry
815a0e
 	}
815a0e
 #endif
815a0e
 
815a0e
-	*jobenv = build_env(e->envp);
815a0e
-
815a0e
 #ifdef WITH_SELINUX
815a0e
 	/* we must get the crontab context BEFORE changing user, else
815a0e
 	 * we'll not be permitted to read the cron spool directory :-)
815a0e
 	 */
815a0e
 	security_context_t ucontext = 0;
815a0e
 
815a0e
-	if (cron_get_job_range(u, &ucontext, *jobenv) < OK) {
815a0e
+	if (cron_get_job_range(u, &ucontext, e->envp) < OK) {
815a0e
 		log_it(e->pwd->pw_name, getpid(), "ERROR",
815a0e
 			"failed to get SELinux context", 0);
815a0e
 		return -1;
815a0e
@@ -165,6 +163,8 @@ int cron_set_job_security_context(entry
815a0e
 		return -1;
815a0e
 	}
815a0e
 
815a0e
+	*jobenv = build_env(e->envp);
815a0e
+
815a0e
 	time_t job_run_time = time(0L);
815a0e
 
815a0e
 	if ((minutely_time > 0) && ((job_run_time / 60) != (minutely_time / 60))) {
815a0e
@@ -615,11 +615,18 @@ int crontab_security_access(void) {
815a0e
 */
815a0e
 static char **build_env(char **cronenv) {
815a0e
 #ifdef WITH_PAM
815a0e
-	char **jobenv;
815a0e
-	char **pamenv = pam_getenvlist(pamh);
815a0e
+	char **jobenv = pam_getenvlist(pamh);
815a0e
 	char *cronvar;
815a0e
 	int count = 0;
815a0e
-	jobenv = env_copy(pamenv);
815a0e
+
815a0e
+	if (jobenv == NULL) {
815a0e
+		jobenv = env_init();
815a0e
+		if (jobenv == NULL) {
815a0e
+			log_it("CRON", getpid(),
815a0e
+				"ERROR", "Initialization of cron environment variables failed", 0);
815a0e
+			return NULL;
815a0e
+		}
815a0e
+	}
815a0e
 
815a0e
 	/* Now add the cron environment variables. Since env_set()
815a0e
 	 * overwrites existing variables, this will let cron's