From b77aa28f46596773110e842d79b65d3fdce9ed22 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sun, 26 Apr 2020 11:12:59 +0000 Subject: pam_motd: fix NULL dereference on error path * modules/pam_motd/pam_motd.c (try_to_display_directories_with_overrides): Do not access elements of dirscans_sizes array if dirscans_sizes == NULL due to an earlier memory allocation error. Fixes: f9c9c721 ("pam_motd: Support multiple motd paths specified, with filename overrides (#69)") --- modules/pam_motd/pam_motd.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'modules/pam_motd') diff --git a/modules/pam_motd/pam_motd.c b/modules/pam_motd/pam_motd.c index a8887ec1..49886d1a 100644 --- a/modules/pam_motd/pam_motd.c +++ b/modules/pam_motd/pam_motd.c @@ -281,15 +281,16 @@ static void try_to_display_directories_with_overrides(pam_handle_t *pamh, out: _pam_drop(dirnames_all); - for (i = 0; i < num_motd_dirs; i++) { - unsigned int j; + if (dirscans_sizes != NULL) { + for (i = 0; i < num_motd_dirs; i++) { + unsigned int j; - for (j = 0; j < dirscans_sizes[i]; j++) { - _pam_drop(dirscans[i][j]); + for (j = 0; j < dirscans_sizes[i]; j++) + _pam_drop(dirscans[i][j]); + _pam_drop(dirscans[i]); } - _pam_drop(dirscans[i]); + _pam_drop(dirscans_sizes); } - _pam_drop(dirscans_sizes); _pam_drop(dirscans); } -- cgit v1.2.3