Skip to content

Commit ceed474

Browse files
Apply suggestions from code review
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent ec05cc8 commit ceed474

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

apps/wolfsshd/test/run_all_sshd_tests.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,21 @@ run_hostkey_perm_check() {
104104
return
105105
fi
106106

107-
HK_WORK=`mktemp -d 2>/dev/null` || HK_WORK=`mktemp -d -t sshdperm`
108-
cp "$HK_KEY" "$HK_WORK/hostkey.pem"
107+
HK_WORK=$(mktemp -d 2>/dev/null) || HK_WORK=$(mktemp -d -t sshdperm)
108+
if [ -z "$HK_WORK" ] || [ ! -d "$HK_WORK" ]; then
109+
printf "SKIPPED (mktemp failed)\n"
110+
SKIPPED=$((SKIPPED+1))
111+
return
112+
fi
113+
114+
cp "$HK_KEY" "$HK_WORK/hostkey.pem" || {
115+
printf "SKIPPED (could not prepare hostkey)\n"
116+
SKIPPED=$((SKIPPED+1))
117+
rm -rf "$HK_WORK"
118+
return
119+
}
109120
chmod 600 "$HK_WORK/hostkey.pem"
110121
touch "$HK_WORK/authorized_keys"
111-
112122
hk_cfg() {
113123
cat > "$HK_WORK/cfg" <<EOF
114124
Port $HK_PORT

apps/wolfsshd/test/start_sshd.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ start_wolfsshd() {
2020
# copies root-owned, and emit a temp config pointing at them. The
2121
# version-controlled files are left untouched so the suite stays re-runnable.
2222
if grep -qE '^(HostKey|HostCertificate|TrustedUserCAKeys)[[:space:]]' "$ORIGCFG"; then
23-
SSHD_KEYDIR=`mktemp -d 2>/dev/null` || SSHD_KEYDIR=`mktemp -d -t sshdkeys`
24-
CONFIG="$SSHD_KEYDIR/sshd_config"
25-
: > "$CONFIG"
23+
SSHD_KEYDIR=$(mktemp -d 2>/dev/null) || SSHD_KEYDIR=$(mktemp -d -t sshdkeys)
24+
if [ -z "$SSHD_KEYDIR" ] || [ ! -d "$SSHD_KEYDIR" ]; then
25+
printf "WARNING: could not create temp dir for trust-anchor copies; using original config\n" >&2
26+
SSHD_KEYDIR=""
27+
else
28+
CONFIG="$SSHD_KEYDIR/sshd_config"
29+
: > "$CONFIG" || { printf "WARNING: could not write %s; using original config\n" "$CONFIG" >&2; CONFIG="$ORIGCFG"; rm -rf "$SSHD_KEYDIR"; SSHD_KEYDIR=""; }
30+
fi
2631
n=0
2732
# Rewrite the config line by line. For each trust-anchor directive copy
2833
# the file to a counter-named destination (so distinct directories with

apps/wolfsshd/wolfsshd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ static int SetupCTX(WOLFSSHD_CONFIG* conf, WOLFSSH_CTX** ctx,
479479
data = getBufferFromFile(hostCert, &dataSz, heap, 1);
480480
if (data == NULL) {
481481
wolfSSH_Log(WS_LOG_ERROR,
482-
"[SSHD] Error reading host key file.");
482+
"[SSHD] Error reading host certificate file.");
483483
ret = WS_MEMORY_E;
484484

485485
}

0 commit comments

Comments
 (0)