Skip to content

Commit

Permalink
Merge pull request #752 from JacobBarthelmeh/wolfsshd
Browse files Browse the repository at this point in the history
fix for handling memory on socket timeout
  • Loading branch information
dgarske authored Nov 15, 2024
2 parents 563e6c4 + d9e5347 commit 735cd89
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/sshd-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,12 @@ jobs:
run: |
git log -3
sudo ./run_all_sshd_tests.sh
# could use optimization with caching
- name: Test memory after close down
working-directory: ./wolfssh/
run: |
sudo apt-get install valgrind
touch sshd_config.txt
./configure --enable-all LDFLAGS="-L${{ github.workspace }}/build-dir/lib" CPPFLAGS="-I${{ github.workspace }}/build-dir/include -DWOLFSSH_NO_FPKI -DWOLFSSH_NO_SFTP_TIMEOUT -DWOLFSSH_MAX_SFTP_RW=4000000 -DMAX_PATH_SZ=120" --enable-static --disable-shared && make
sudo timeout --preserve-status -s 2 5 valgrind --error-exitcode=1 --leak-check=full ./apps/wolfsshd/wolfsshd -D -f sshd_config -h ./keys/server-key.pem -d -p 22222
12 changes: 9 additions & 3 deletions apps/wolfsshd/wolfsshd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2468,9 +2468,11 @@ static int StartSSHD(int argc, char** argv)
struct sockaddr_in6 clientAddr;
socklen_t clientAddrSz = sizeof(clientAddr);
#endif
conn = (WOLFSSHD_CONNECTION*)WMALLOC(sizeof(WOLFSSHD_CONNECTION), NULL, DYNTYPE_SSHD);
conn = (WOLFSSHD_CONNECTION*)WMALLOC(sizeof(WOLFSSHD_CONNECTION),
NULL, DYNTYPE_SSHD);
if (conn == NULL) {
wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Failed to malloc memory for connection");
wolfSSH_Log(WS_LOG_ERROR,
"[SSHD] Failed to malloc memory for connection");
break;
}

Expand Down Expand Up @@ -2536,9 +2538,13 @@ static int StartSSHD(int argc, char** argv)
}
ret = NewConnection(conn);
}
else {
XFREE(conn, NULL, DYNTYPE_SSHD);
}
#ifdef _WIN32
/* check if service has been shutdown */
if (isDaemon && WaitForSingleObject(serviceStop, 0) == WAIT_OBJECT_0) {
if (isDaemon && WaitForSingleObject(serviceStop, 0) ==
WAIT_OBJECT_0) {
quit = 1;
}
#endif
Expand Down

0 comments on commit 735cd89

Please sign in to comment.