From 70ee22ba4414b47dcd4ea2dfb8f3ba462b38718d Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sun, 26 Apr 2020 11:12:59 +0000 Subject: pam_motd: fix misleading error diagnostics Do not invoke calloc with the first argument equal to zero as the return value can be NULL which is undistinguishable from memory allocation error. * modules/pam_motd/pam_motd.c (try_to_display_directories_with_overrides): Skip if there are no directory entries (dirscans_size_total == 0). Fixes: f9c9c721 ("pam_motd: Support multiple motd paths specified, with filename overrides (#69)") --- modules/pam_motd/pam_motd.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'modules/pam_motd') diff --git a/modules/pam_motd/pam_motd.c b/modules/pam_motd/pam_motd.c index 3870d997..f0cd317d 100644 --- a/modules/pam_motd/pam_motd.c +++ b/modules/pam_motd/pam_motd.c @@ -224,6 +224,9 @@ static void try_to_display_directories_with_overrides(pam_handle_t *pamh, dirscans_size_total += dirscans_sizes[i]; } + if (dirscans_size_total == 0) + goto out; + /* Allocate space for all file names found in the directories, including duplicates. */ if ((dirnames_all = calloc(dirscans_size_total, sizeof(char *))) == NULL) { pam_syslog(pamh, LOG_CRIT, "pam_motd: failed to allocate dirname array"); -- cgit v1.2.3