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

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