forked from wolfSSL/wolfssl
make sure example CyaSSL_read()s that fill buffer don't overrun by 1 byte if trying to output with null terminator
This commit is contained in:
@@ -419,14 +419,14 @@ void client_test(void* args)
|
|||||||
if (CyaSSL_write(ssl, msg, msgSz) != msgSz)
|
if (CyaSSL_write(ssl, msg, msgSz) != msgSz)
|
||||||
err_sys("SSL_write failed");
|
err_sys("SSL_write failed");
|
||||||
|
|
||||||
input = CyaSSL_read(ssl, reply, sizeof(reply));
|
input = CyaSSL_read(ssl, reply, sizeof(reply)-1);
|
||||||
if (input > 0) {
|
if (input > 0) {
|
||||||
reply[input] = 0;
|
reply[input] = 0;
|
||||||
printf("Server response: %s\n", reply);
|
printf("Server response: %s\n", reply);
|
||||||
|
|
||||||
if (sendGET) { /* get html */
|
if (sendGET) { /* get html */
|
||||||
while (1) {
|
while (1) {
|
||||||
input = CyaSSL_read(ssl, reply, sizeof(reply));
|
input = CyaSSL_read(ssl, reply, sizeof(reply)-1);
|
||||||
if (input > 0) {
|
if (input > 0) {
|
||||||
reply[input] = 0;
|
reply[input] = 0;
|
||||||
printf("%s\n", reply);
|
printf("%s\n", reply);
|
||||||
@@ -510,7 +510,7 @@ void client_test(void* args)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
input = CyaSSL_read(sslResume, reply, sizeof(reply));
|
input = CyaSSL_read(sslResume, reply, sizeof(reply)-1);
|
||||||
if (input > 0) {
|
if (input > 0) {
|
||||||
reply[input] = 0;
|
reply[input] = 0;
|
||||||
printf("Server resume response: %s\n", reply);
|
printf("Server resume response: %s\n", reply);
|
||||||
|
@@ -39,7 +39,7 @@ void echoclient_test(void* args)
|
|||||||
int outCreated = 0;
|
int outCreated = 0;
|
||||||
|
|
||||||
char msg[1024];
|
char msg[1024];
|
||||||
char reply[1024];
|
char reply[1024+1];
|
||||||
|
|
||||||
SSL_METHOD* method = 0;
|
SSL_METHOD* method = 0;
|
||||||
SSL_CTX* ctx = 0;
|
SSL_CTX* ctx = 0;
|
||||||
@@ -148,7 +148,7 @@ void echoclient_test(void* args)
|
|||||||
|
|
||||||
while (sendSz) {
|
while (sendSz) {
|
||||||
int got;
|
int got;
|
||||||
if ( (got = SSL_read(ssl, reply, sizeof(reply))) > 0) {
|
if ( (got = SSL_read(ssl, reply, sizeof(reply)-1)) > 0) {
|
||||||
reply[got] = 0;
|
reply[got] = 0;
|
||||||
fputs(reply, fout);
|
fputs(reply, fout);
|
||||||
sendSz -= got;
|
sendSz -= got;
|
||||||
|
@@ -163,7 +163,7 @@ THREAD_RETURN CYASSL_THREAD echoserver_test(void* args)
|
|||||||
|
|
||||||
while (!shutDown) {
|
while (!shutDown) {
|
||||||
CYASSL* ssl = 0;
|
CYASSL* ssl = 0;
|
||||||
char command[1024];
|
char command[1024+1];
|
||||||
int echoSz = 0;
|
int echoSz = 0;
|
||||||
int clientfd;
|
int clientfd;
|
||||||
int firstRead = 1;
|
int firstRead = 1;
|
||||||
@@ -197,7 +197,7 @@ THREAD_RETURN CYASSL_THREAD echoserver_test(void* args)
|
|||||||
showPeer(ssl);
|
showPeer(ssl);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while ( (echoSz = CyaSSL_read(ssl, command, sizeof(command))) > 0) {
|
while ( (echoSz = CyaSSL_read(ssl, command, sizeof(command)-1)) > 0) {
|
||||||
|
|
||||||
if (firstRead == 1) {
|
if (firstRead == 1) {
|
||||||
firstRead = 0; /* browser may send 1 byte 'G' to start */
|
firstRead = 0; /* browser may send 1 byte 'G' to start */
|
||||||
|
@@ -351,7 +351,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
|||||||
#endif
|
#endif
|
||||||
showPeer(ssl);
|
showPeer(ssl);
|
||||||
|
|
||||||
idx = SSL_read(ssl, input, sizeof(input));
|
idx = SSL_read(ssl, input, sizeof(input)-1);
|
||||||
if (idx > 0) {
|
if (idx > 0) {
|
||||||
input[idx] = 0;
|
input[idx] = 0;
|
||||||
printf("Client message: %s\n", input);
|
printf("Client message: %s\n", input);
|
||||||
|
@@ -214,13 +214,13 @@ void client_test(void) {
|
|||||||
if (CyaSSL_write(ssl, msg, msgSz) != msgSz)
|
if (CyaSSL_write(ssl, msg, msgSz) != msgSz)
|
||||||
err_sys("CyaSSL_write() failed");
|
err_sys("CyaSSL_write() failed");
|
||||||
|
|
||||||
input = CyaSSL_read(ssl, reply, sizeof(reply));
|
input = CyaSSL_read(ssl, reply, sizeof(reply)-1);
|
||||||
if (input > 0) {
|
if (input > 0) {
|
||||||
reply[input] = 0;
|
reply[input] = 0;
|
||||||
printf("Server response: %s\n", reply);
|
printf("Server response: %s\n", reply);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
input = CyaSSL_read(ssl, reply, sizeof(reply));
|
input = CyaSSL_read(ssl, reply, sizeof(reply)-1);
|
||||||
if (input > 0) {
|
if (input > 0) {
|
||||||
reply[input] = 0;
|
reply[input] = 0;
|
||||||
printf("%s\n", reply);
|
printf("%s\n", reply);
|
||||||
|
@@ -651,7 +651,7 @@ THREAD_RETURN CYASSL_THREAD test_server_nofail(void* args)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
idx = CyaSSL_read(ssl, input, sizeof(input));
|
idx = CyaSSL_read(ssl, input, sizeof(input)-1);
|
||||||
if (idx > 0) {
|
if (idx > 0) {
|
||||||
input[idx] = 0;
|
input[idx] = 0;
|
||||||
printf("Client message: %s\n", input);
|
printf("Client message: %s\n", input);
|
||||||
@@ -732,7 +732,7 @@ void test_client_nofail(void* args)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
input = CyaSSL_read(ssl, reply, sizeof(reply));
|
input = CyaSSL_read(ssl, reply, sizeof(reply)-1);
|
||||||
if (input > 0)
|
if (input > 0)
|
||||||
{
|
{
|
||||||
reply[input] = 0;
|
reply[input] = 0;
|
||||||
|
Reference in New Issue
Block a user