Skip to content

Commit

Permalink
Fix StartTLS_Init (#5907)
Browse files Browse the repository at this point in the history
* Fix StartTLS_Init (contribution by Yota Nagaya)
  • Loading branch information
yota22721 authored Jan 3, 2023
1 parent c925223 commit 4edae51
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions examples/client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,8 @@ static int StartTLS_Init(SOCKET_T* sockfd)
if (recv(*sockfd, tmpBuf, sizeof(tmpBuf)-1, 0) < 0)
err_sys("failed to read STARTTLS command\n");

if (!XSTRCMP(tmpBuf, starttlsCmd[0])) {
if ((!XSTRNCMP(tmpBuf, starttlsCmd[0], XSTRLEN(starttlsCmd[0]))) &&
(tmpBuf[XSTRLEN(starttlsCmd[0])] == ' ')) {
printf("%s\n", tmpBuf);
} else {
err_sys("incorrect STARTTLS command received");
Expand All @@ -859,7 +860,8 @@ static int StartTLS_Init(SOCKET_T* sockfd)
if (recv(*sockfd, tmpBuf, sizeof(tmpBuf)-1, 0) < 0)
err_sys("failed to read STARTTLS command\n");

if (!XSTRCMP(tmpBuf, starttlsCmd[2])) {
if ((!XSTRNCMP(tmpBuf, starttlsCmd[2], XSTRLEN(starttlsCmd[2]))) &&
(tmpBuf[XSTRLEN(starttlsCmd[2])] == '-')) {
printf("%s\n", tmpBuf);
} else {
err_sys("incorrect STARTTLS command received");
Expand All @@ -876,7 +878,9 @@ static int StartTLS_Init(SOCKET_T* sockfd)
if (recv(*sockfd, tmpBuf, sizeof(tmpBuf)-1, 0) < 0)
err_sys("failed to read STARTTLS command\n");
tmpBuf[sizeof(tmpBuf)-1] = '\0';
if (!XSTRCMP(tmpBuf, starttlsCmd[4])) {

if ((!XSTRNCMP(tmpBuf, starttlsCmd[4], XSTRLEN(starttlsCmd[4]))) &&
(tmpBuf[XSTRLEN(starttlsCmd[4])] == ' ')) {
printf("%s\n", tmpBuf);
} else {
err_sys("incorrect STARTTLS command received, expected 220");
Expand Down

0 comments on commit 4edae51

Please sign in to comment.