|
|
c28ff7 |
From 62cd745d730e5ba13d5d7092ac566fc0b2148e61 Mon Sep 17 00:00:00 2001
|
|
|
c28ff7 |
From: "Dmitry V. Levin" <ldv@altlinux.org>
|
|
|
c28ff7 |
Date: Sun, 26 Apr 2020 11:12:59 +0000
|
|
|
c28ff7 |
Subject: [PATCH] pam_motd: fix memory leak
|
|
|
c28ff7 |
|
|
|
c28ff7 |
pam_motd used to leak memory allocated for each motd file
|
|
|
c28ff7 |
successfully opened in try_to_display_directories_with_overrides.
|
|
|
c28ff7 |
|
|
|
c28ff7 |
* modules/pam_motd/pam_motd.c
|
|
|
c28ff7 |
(try_to_display_directories_with_overrides): Free abs_path.
|
|
|
c28ff7 |
|
|
|
c28ff7 |
Fixes: f9c9c721 ("pam_motd: Support multiple motd paths specified, with filename overrides (#69)")
|
|
|
c28ff7 |
---
|
|
|
c28ff7 |
modules/pam_motd/pam_motd.c | 20 ++++++++++----------
|
|
|
c28ff7 |
1 file changed, 10 insertions(+), 10 deletions(-)
|
|
|
c28ff7 |
|
|
|
c28ff7 |
diff --git a/modules/pam_motd/pam_motd.c b/modules/pam_motd/pam_motd.c
|
|
|
c28ff7 |
index f0cd317d..3be129a5 100644
|
|
|
c28ff7 |
--- a/modules/pam_motd/pam_motd.c
|
|
|
c28ff7 |
+++ b/modules/pam_motd/pam_motd.c
|
|
|
c28ff7 |
@@ -259,23 +259,23 @@ static void try_to_display_directories_with_overrides(pam_handle_t *pamh,
|
|
|
c28ff7 |
|
|
|
c28ff7 |
for (j = 0; j < num_motd_dirs; j++) {
|
|
|
c28ff7 |
char *abs_path = NULL;
|
|
|
c28ff7 |
+ int fd;
|
|
|
c28ff7 |
|
|
|
c28ff7 |
if (join_dir_strings(&abs_path, motd_dir_path_split[j],
|
|
|
c28ff7 |
- dirnames_all[i]) < 0) {
|
|
|
c28ff7 |
+ dirnames_all[i]) < 0 || abs_path == NULL) {
|
|
|
c28ff7 |
continue;
|
|
|
c28ff7 |
}
|
|
|
c28ff7 |
|
|
|
c28ff7 |
- if (abs_path != NULL) {
|
|
|
c28ff7 |
- int fd = open(abs_path, O_RDONLY, 0);
|
|
|
c28ff7 |
- if (fd >= 0) {
|
|
|
c28ff7 |
- try_to_display_fd(pamh, fd);
|
|
|
c28ff7 |
- close(fd);
|
|
|
c28ff7 |
+ fd = open(abs_path, O_RDONLY, 0);
|
|
|
c28ff7 |
+ _pam_drop(abs_path);
|
|
|
c28ff7 |
|
|
|
c28ff7 |
- /* We displayed a file, skip to the next file name. */
|
|
|
c28ff7 |
- break;
|
|
|
c28ff7 |
- }
|
|
|
c28ff7 |
+ if (fd >= 0) {
|
|
|
c28ff7 |
+ try_to_display_fd(pamh, fd);
|
|
|
c28ff7 |
+ close(fd);
|
|
|
c28ff7 |
+
|
|
|
c28ff7 |
+ /* We displayed a file, skip to the next file name. */
|
|
|
c28ff7 |
+ break;
|
|
|
c28ff7 |
}
|
|
|
c28ff7 |
- _pam_drop(abs_path);
|
|
|
c28ff7 |
}
|
|
|
c28ff7 |
}
|
|
|
c28ff7 |
|
|
|
c28ff7 |
--
|
|
|
c28ff7 |
2.35.3
|
|
|
c28ff7 |
|