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:
toddouska
2013-02-08 11:21:48 -08:00
parent 44e0d7543c
commit 8ace08499b
6 changed files with 12 additions and 12 deletions

View File

@@ -419,14 +419,14 @@ void client_test(void* args)
if (CyaSSL_write(ssl, msg, msgSz) != msgSz)
err_sys("SSL_write failed");
input = CyaSSL_read(ssl, reply, sizeof(reply));
input = CyaSSL_read(ssl, reply, sizeof(reply)-1);
if (input > 0) {
reply[input] = 0;
printf("Server response: %s\n", reply);
if (sendGET) { /* get html */
while (1) {
input = CyaSSL_read(ssl, reply, sizeof(reply));
input = CyaSSL_read(ssl, reply, sizeof(reply)-1);
if (input > 0) {
reply[input] = 0;
printf("%s\n", reply);
@@ -510,7 +510,7 @@ void client_test(void* args)
#endif
}
input = CyaSSL_read(sslResume, reply, sizeof(reply));
input = CyaSSL_read(sslResume, reply, sizeof(reply)-1);
if (input > 0) {
reply[input] = 0;
printf("Server resume response: %s\n", reply);

View File

@@ -39,7 +39,7 @@ void echoclient_test(void* args)
int outCreated = 0;
char msg[1024];
char reply[1024];
char reply[1024+1];
SSL_METHOD* method = 0;
SSL_CTX* ctx = 0;
@@ -148,7 +148,7 @@ void echoclient_test(void* args)
while (sendSz) {
int got;
if ( (got = SSL_read(ssl, reply, sizeof(reply))) > 0) {
if ( (got = SSL_read(ssl, reply, sizeof(reply)-1)) > 0) {
reply[got] = 0;
fputs(reply, fout);
sendSz -= got;

View File

@@ -163,7 +163,7 @@ THREAD_RETURN CYASSL_THREAD echoserver_test(void* args)
while (!shutDown) {
CYASSL* ssl = 0;
char command[1024];
char command[1024+1];
int echoSz = 0;
int clientfd;
int firstRead = 1;
@@ -197,7 +197,7 @@ THREAD_RETURN CYASSL_THREAD echoserver_test(void* args)
showPeer(ssl);
#endif
while ( (echoSz = CyaSSL_read(ssl, command, sizeof(command))) > 0) {
while ( (echoSz = CyaSSL_read(ssl, command, sizeof(command)-1)) > 0) {
if (firstRead == 1) {
firstRead = 0; /* browser may send 1 byte 'G' to start */

View File

@@ -351,7 +351,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
#endif
showPeer(ssl);
idx = SSL_read(ssl, input, sizeof(input));
idx = SSL_read(ssl, input, sizeof(input)-1);
if (idx > 0) {
input[idx] = 0;
printf("Client message: %s\n", input);

View File

@@ -214,13 +214,13 @@ void client_test(void) {
if (CyaSSL_write(ssl, msg, msgSz) != msgSz)
err_sys("CyaSSL_write() failed");
input = CyaSSL_read(ssl, reply, sizeof(reply));
input = CyaSSL_read(ssl, reply, sizeof(reply)-1);
if (input > 0) {
reply[input] = 0;
printf("Server response: %s\n", reply);
while(1) {
input = CyaSSL_read(ssl, reply, sizeof(reply));
input = CyaSSL_read(ssl, reply, sizeof(reply)-1);
if (input > 0) {
reply[input] = 0;
printf("%s\n", reply);

View File

@@ -651,7 +651,7 @@ THREAD_RETURN CYASSL_THREAD test_server_nofail(void* args)
return 0;
}
idx = CyaSSL_read(ssl, input, sizeof(input));
idx = CyaSSL_read(ssl, input, sizeof(input)-1);
if (idx > 0) {
input[idx] = 0;
printf("Client message: %s\n", input);
@@ -732,7 +732,7 @@ void test_client_nofail(void* args)
return;
}
input = CyaSSL_read(ssl, reply, sizeof(reply));
input = CyaSSL_read(ssl, reply, sizeof(reply)-1);
if (input > 0)
{
reply[input] = 0;