git: cca0ce62f367 - main - pam_xdg: pam_get_item can return NULL

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Mon, 27 May 2024 06:33:30 UTC
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=cca0ce62f367d03ed429bf99e41e6aca8cb7f2ac

commit cca0ce62f367d03ed429bf99e41e6aca8cb7f2ac
Author:     Andre Albsmeier <mail@fbsd2.e4m.org>
AuthorDate: 2024-05-27 06:31:34 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2024-05-27 06:33:14 +0000

    pam_xdg: pam_get_item can return NULL
    
    Fix pam_xdg as pam_get_item can return NULL, this happens when pressing
    control + C in xdm for example.
    
    MFC after:      1 week
    PR:             279268
---
 lib/libpam/modules/pam_xdg/pam_xdg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/libpam/modules/pam_xdg/pam_xdg.c b/lib/libpam/modules/pam_xdg/pam_xdg.c
index 4d586a21566a..2c80f0a0332f 100644
--- a/lib/libpam/modules/pam_xdg/pam_xdg.c
+++ b/lib/libpam/modules/pam_xdg/pam_xdg.c
@@ -67,7 +67,7 @@ _pam_xdg_open(pam_handle_t *pamh, int flags __unused,
 
 	/* Get user info */
 	rv = pam_get_item(pamh, PAM_USER, (const void **)&user);
-	if (rv != PAM_SUCCESS) {
+	if (rv != PAM_SUCCESS || user == NULL) {
 		PAM_VERBOSE_ERROR("Can't get user information");
 		goto out;
 	}
@@ -221,7 +221,7 @@ _pam_xdg_close(pam_handle_t *pamh __unused, int flags __unused,
 
 	/* Get user info */
 	rv = pam_get_item(pamh, PAM_USER, (const void **)&user);
-	if (rv != PAM_SUCCESS) {
+	if (rv != PAM_SUCCESS || user == NULL) {
 		PAM_VERBOSE_ERROR("Can't get user information");
 		goto out;
 	}