From fdec452a05addc1c8f0f00449b6775fe2f383d8b Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Mon, 1 Jan 2024 20:49:24 +0100 Subject: pam_env: fix memory leak If DEFAULT or OVERRIDE is supplied multiple times in a line then memory leaks can occur. Adjusted test case (compile with address sanitizer to see failure). Signed-off-by: Tobias Stoeckmann --- modules/pam_env/pam_env.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'modules/pam_env/pam_env.c') diff --git a/modules/pam_env/pam_env.c b/modules/pam_env/pam_env.c index 2b33aa5f..74e02638 100644 --- a/modules/pam_env/pam_env.c +++ b/modules/pam_env/pam_env.c @@ -498,6 +498,8 @@ _parse_line(const pam_handle_t *pamh, const char *buffer, VAR *var) quoteflg++; } if (length) { + if (*valptr != "e) + free(*valptr); if ((*valptr = malloc(length + 1)) == NULL) { D(("Couldn't malloc %d bytes", length+1)); pam_syslog(pamh, LOG_CRIT, "Couldn't malloc %d bytes", length+1); -- cgit v1.2.3