Blame SOURCES/pam-1.3.1-pam-motd-fix-segmentation-fault.patch

c28ff7
From 8eaf5570cf011148a0b55c53570df5edaafebdb0 Mon Sep 17 00:00:00 2001
c28ff7
From: Robert Fairley <rfairley@users.noreply.github.com>
c28ff7
Date: Wed, 21 Nov 2018 02:46:02 -0500
c28ff7
Subject: [PATCH] pam_motd: Fix segmentation fault when no motd_dir specified
c28ff7
 (#76)
c28ff7
c28ff7
This fixes a regression introduced by #69, where motd_path was set
c28ff7
to NULL and passed into strdup() if the motd_dir argument was
c28ff7
not specified in the configuration file. This caused a segmentation
c28ff7
fault.
c28ff7
c28ff7
* modules/pam_motd/pam_motd.c: fix checks for NULL in arguments
c28ff7
* xtests/Makefile.am: add test scripts and config file
c28ff7
* xtests/tst-pam_motd.sh: add running tst-pam_motd4.sh
c28ff7
* xtests/tst-pam_motd4.pamd: create
c28ff7
* xtests/tst-pam_motd4.sh: create
c28ff7
---
c28ff7
 modules/pam_motd/pam_motd.c | 15 ++++++++++-----
c28ff7
 xtests/Makefile.am          |  4 ++--
c28ff7
 xtests/tst-pam_motd.sh      |  1 +
c28ff7
 xtests/tst-pam_motd4.pamd   |  3 +++
c28ff7
 xtests/tst-pam_motd4.sh     | 27 +++++++++++++++++++++++++++
c28ff7
 5 files changed, 43 insertions(+), 7 deletions(-)
c28ff7
 create mode 100644 xtests/tst-pam_motd4.pamd
c28ff7
 create mode 100755 xtests/tst-pam_motd4.sh
c28ff7
c28ff7
diff --git a/modules/pam_motd/pam_motd.c b/modules/pam_motd/pam_motd.c
c28ff7
index 1c1cfcfa..ec3ebd58 100644
c28ff7
--- a/modules/pam_motd/pam_motd.c
c28ff7
+++ b/modules/pam_motd/pam_motd.c
c28ff7
@@ -132,7 +132,6 @@ static int pam_split_string(const pam_handle_t *pamh, char *arg, char delim,
c28ff7
 	goto out;
c28ff7
     }
c28ff7
 
c28ff7
-
c28ff7
     arg_extracted = strtok_r(arg, delim_str, &arg;;
c28ff7
     while (arg_extracted != NULL && i < num_strs) {
c28ff7
 	arg_split[i++] = arg_extracted;
c28ff7
@@ -363,15 +362,21 @@ int pam_sm_open_session(pam_handle_t *pamh, int flags,
c28ff7
 	motd_dir_path = default_motd_dir;
c28ff7
     }
c28ff7
 
c28ff7
-    motd_path_copy = strdup(motd_path);
c28ff7
+    if (motd_path != NULL) {
c28ff7
+	motd_path_copy = strdup(motd_path);
c28ff7
+    }
c28ff7
+
c28ff7
     if (motd_path_copy != NULL) {
c28ff7
-	if (pam_split_string(pamh, motd_path_copy, ':', &motd_path_split,
c28ff7
-		&num_motd_paths) == 0) {
c28ff7
+	if (pam_split_string(pamh, motd_path_copy, ':',
c28ff7
+		&motd_path_split, &num_motd_paths) == 0) {
c28ff7
 	    goto out;
c28ff7
 	}
c28ff7
     }
c28ff7
 
c28ff7
-    motd_dir_path_copy = strdup(motd_dir_path);
c28ff7
+    if (motd_dir_path != NULL) {
c28ff7
+	motd_dir_path_copy = strdup(motd_dir_path);
c28ff7
+    }
c28ff7
+
c28ff7
     if (motd_dir_path_copy != NULL) {
c28ff7
 	if (pam_split_string(pamh, motd_dir_path_copy, ':',
c28ff7
 		&motd_dir_path_split, &num_motd_dir_paths) == 0) {
c28ff7
diff --git a/xtests/Makefile.am b/xtests/Makefile.am
c28ff7
index 555d5e33..4d5aba3d 100644
c28ff7
--- a/xtests/Makefile.am
c28ff7
+++ b/xtests/Makefile.am
c28ff7
@@ -34,8 +34,8 @@ EXTRA_DIST = run-xtests.sh tst-pam_dispatch1.pamd tst-pam_dispatch2.pamd \
c28ff7
 	tst-pam_pwhistory1.pamd tst-pam_pwhistory1.sh \
c28ff7
 	tst-pam_time1.pamd time.conf \
c28ff7
 	tst-pam_motd.sh tst-pam_motd1.sh tst-pam_motd2.sh \
c28ff7
-	tst-pam_motd3.sh tst-pam_motd1.pamd \
c28ff7
-	tst-pam_motd2.pamd tst-pam_motd3.pamd
c28ff7
+	tst-pam_motd3.sh tst-pam_motd4.sh tst-pam_motd1.pamd \
c28ff7
+	tst-pam_motd2.pamd tst-pam_motd3.pamd tst-pam_motd4.pamd
c28ff7
 
c28ff7
 XTESTS = tst-pam_dispatch1 tst-pam_dispatch2 tst-pam_dispatch3 \
c28ff7
 	tst-pam_dispatch4 tst-pam_dispatch5 \
c28ff7
diff --git a/xtests/tst-pam_motd.sh b/xtests/tst-pam_motd.sh
c28ff7
index 9b0c38f6..90801280 100755
c28ff7
--- a/xtests/tst-pam_motd.sh
c28ff7
+++ b/xtests/tst-pam_motd.sh
c28ff7
@@ -5,3 +5,4 @@ set -e
c28ff7
 ./tst-pam_motd1.sh
c28ff7
 ./tst-pam_motd2.sh
c28ff7
 ./tst-pam_motd3.sh
c28ff7
+./tst-pam_motd4.sh
c28ff7
diff --git a/xtests/tst-pam_motd4.pamd b/xtests/tst-pam_motd4.pamd
c28ff7
new file mode 100644
c28ff7
index 00000000..9dc311ad
c28ff7
--- /dev/null
c28ff7
+++ b/xtests/tst-pam_motd4.pamd
c28ff7
@@ -0,0 +1,3 @@
c28ff7
+#%PAM-1.0
c28ff7
+session    required    pam_permit.so
c28ff7
+session    optional    pam_motd.so motd=tst-pam_motd4.d/etc/motd
c28ff7
diff --git a/xtests/tst-pam_motd4.sh b/xtests/tst-pam_motd4.sh
c28ff7
new file mode 100755
c28ff7
index 00000000..6022177f
c28ff7
--- /dev/null
c28ff7
+++ b/xtests/tst-pam_motd4.sh
c28ff7
@@ -0,0 +1,27 @@
c28ff7
+#!/bin/bash
c28ff7
+
c28ff7
+TST_DIR="tst-pam_motd4.d"
c28ff7
+
c28ff7
+function tst_cleanup() {
c28ff7
+    rm -rf "${TST_DIR}"
c28ff7
+    rm -f tst-pam_motd4.out
c28ff7
+}
c28ff7
+
c28ff7
+mkdir -p ${TST_DIR}/etc
c28ff7
+
c28ff7
+# Verify the case of single motd with no motd_dir given in tst-pam_motd4.pamd
c28ff7
+echo "motd: /etc/motd" > ${TST_DIR}/etc/motd
c28ff7
+
c28ff7
+./tst-pam_motd tst-pam_motd4 > tst-pam_motd4.out
c28ff7
+
c28ff7
+RET=$?
c28ff7
+
c28ff7
+motd_to_show_output=$(cat tst-pam_motd4.out | grep "motd: /etc/motd")
c28ff7
+if [ -z "${motd_to_show_output}" ];
c28ff7
+then
c28ff7
+    tst_cleanup
c28ff7
+    exit 1
c28ff7
+fi
c28ff7
+
c28ff7
+tst_cleanup
c28ff7
+exit $RET
c28ff7
-- 
c28ff7
2.35.1
c28ff7