File pam-bsc1177858-dont-free-environment-string.patch of Package pam.21584

Index: Linux-PAM-1.3.0/modules/pam_xauth/pam_xauth.c
===================================================================
--- Linux-PAM-1.3.0.orig/modules/pam_xauth/pam_xauth.c
+++ Linux-PAM-1.3.0/modules/pam_xauth/pam_xauth.c
@@ -697,8 +697,9 @@ pam_sm_open_session (pam_handle_t *pamh,
 			pam_syslog(pamh, LOG_ERR,
 				   "can't set environment variable '%s'",
 				   xauthority);
-		putenv (xauthority); /* The environment owns this string now. */
-		/* Don't free environment variables nor set them to NULL. */
+		if (putenv (xauthority) == 0) /* The environment owns this string now. */
+		    xauthority = NULL;
+		/* Don't free environment variables. */
 
 		/* set $DISPLAY in pam handle to make su - work */
 		{
@@ -761,7 +762,8 @@ cleanup:
 		unsetenv (XAUTHENV);
 	free(cookiefile);
 	free(cookie);
-	free(xauthority);
+	if (xauthority != NULL)	/* If it hasn't been successfully passed to putenv() ... */
+	    free(xauthority);
 	return retval;
 }
 
openSUSE Build Service is sponsored by