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