Skip to content

Commit b86dc9a

Browse files
authored
Merge pull request #753 from JacobBarthelmeh/wolfsshd_shell
kill child process after SSH connection failure
2 parents 735cd89 + ce5b401 commit b86dc9a

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

apps/wolfsshd/test/run_all_sshd_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ run_test "sshd_exec_test.sh"
6161
run_test "sshd_term_size_test.sh"
6262
run_test "sshd_large_sftp_test.sh"
6363
run_test "sshd_bad_sftp_test.sh"
64+
run_test "sshd_term_close_test.sh"
6465

6566
#Github actions needs resolved for these test cases
6667
#run_test "error_return.sh"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/sh
2+
3+
# sshd local test
4+
5+
ROOT_PWD=$(pwd)
6+
cd ../../..
7+
8+
TEST_CLIENT="./examples/client/client"
9+
PRIVATE_KEY="./keys/hansel-key-ecc.der"
10+
PUBLIC_KEY="./keys/hansel-key-ecc.pub"
11+
12+
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
13+
echo "expecting host and port as arguments"
14+
echo "$0 127.0.0.1 22222 $USER"
15+
exit 1
16+
fi
17+
18+
# get the current wolfsshd pid count to compare with
19+
WOLFSSHD_PID_COUNT=$(pgrep wolfsshd | wc -l)
20+
21+
timeout 3 $TEST_CLIENT -p $2 -i $PRIVATE_KEY -j $PUBLIC_KEY -h $1 -c '/bin/sleep 10' -u $3 &
22+
sleep 1
23+
WOLFSSHD_PID_COUNT_AFTER=$(pgrep wolfsshd | wc -l)
24+
if [ "$WOLFSSHD_PID_COUNT" = "$WOLFSSHD_PID_COUNT_AFTER" ]; then
25+
echo "Expecting another wolfSSHd pid after connection"
26+
echo "PID count before = $WOLFSSHD_PID_COUNT"
27+
echo "PID count after = $WOLFSSHD_PID_COUNT_AFTER"
28+
exit 1
29+
fi
30+
31+
netstat -nt | grep ESTABLISHED
32+
RESULT=$?
33+
if [ "$RESULT" != "0" ]; then
34+
echo "Expecting to find the TCP connection established"
35+
exit 1
36+
fi
37+
38+
sleep 2
39+
40+
netstat -nt | grep CLOSE_WAIT
41+
RESULT=$?
42+
if [ "$RESULT" = "0" ]; then
43+
echo "Found close wait and was not expecting it"
44+
exit 1
45+
fi
46+
47+
netstat -nt | grep TIME_WAIT
48+
RESULT=$?
49+
if [ "$RESULT" != "0" ]; then
50+
echo "Did not find timed wait for TCP close down"
51+
exit 1
52+
fi
53+
54+
cd "$ROOT_PWD"
55+
exit 0
56+
57+

apps/wolfsshd/wolfsshd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,8 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
14981498
continue;
14991499
}
15001500
else if (rc != WS_WANT_READ) {
1501+
/* unexpected error, kill off child process */
1502+
kill(childPid, SIGKILL);
15011503
break;
15021504
}
15031505
}

0 commit comments

Comments
 (0)