From 8eaf5570cf011148a0b55c53570df5edaafebdb0 Mon Sep 17 00:00:00 2001 From: Robert Fairley Date: Wed, 21 Nov 2018 02:46:02 -0500 Subject: pam_motd: Fix segmentation fault when no motd_dir specified (#76) This fixes a regression introduced by #69, where motd_path was set to NULL and passed into strdup() if the motd_dir argument was not specified in the configuration file. This caused a segmentation fault. * modules/pam_motd/pam_motd.c: fix checks for NULL in arguments * xtests/Makefile.am: add test scripts and config file * xtests/tst-pam_motd.sh: add running tst-pam_motd4.sh * xtests/tst-pam_motd4.pamd: create * xtests/tst-pam_motd4.sh: create --- modules/pam_motd/pam_motd.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/pam_motd/pam_motd.c b/modules/pam_motd/pam_motd.c index 1c1cfcfa..ec3ebd58 100644 --- a/modules/pam_motd/pam_motd.c +++ b/modules/pam_motd/pam_motd.c @@ -132,7 +132,6 @@ static int pam_split_string(const pam_handle_t *pamh, char *arg, char delim, goto out; } - arg_extracted = strtok_r(arg, delim_str, &arg); while (arg_extracted != NULL && i < num_strs) { arg_split[i++] = arg_extracted; @@ -363,15 +362,21 @@ int pam_sm_open_session(pam_handle_t *pamh, int flags, motd_dir_path = default_motd_dir; } - motd_path_copy = strdup(motd_path); + if (motd_path != NULL) { + motd_path_copy = strdup(motd_path); + } + if (motd_path_copy != NULL) { - if (pam_split_string(pamh, motd_path_copy, ':', &motd_path_split, - &num_motd_paths) == 0) { + if (pam_split_string(pamh, motd_path_copy, ':', + &motd_path_split, &num_motd_paths) == 0) { goto out; } } - motd_dir_path_copy = strdup(motd_dir_path); + if (motd_dir_path != NULL) { + motd_dir_path_copy = strdup(motd_dir_path); + } + if (motd_dir_path_copy != NULL) { if (pam_split_string(pamh, motd_dir_path_copy, ':', &motd_dir_path_split, &num_motd_dir_paths) == 0) { -- cgit v1.2.3