Fix some undefined behaviour in stack test
[openssl.git] / test / sslapitest.c
index 331790bfdf5cb0310f44fc0864b61b34e4d9a625..85fcabc66c930a2f10e4c8c6c270c3023bbaeb83 100644 (file)
@@ -1604,14 +1604,14 @@ static int test_early_data_read_write(void)
         goto end;
 
     /* Write and read some early data */
-    if (!SSL_write_early(clientssl, MSG1, strlen(MSG1), &written)
+    if (!SSL_write_early_data(clientssl, MSG1, strlen(MSG1), &written)
             || written != strlen(MSG1)) {
         printf("Failed writing early data message 1\n");
         goto end;
     }
 
-    if (SSL_read_early(serverssl, buf, sizeof(buf), &readbytes)
-                != SSL_READ_EARLY_SUCCESS
+    if (SSL_read_early_data(serverssl, buf, sizeof(buf), &readbytes)
+                != SSL_READ_EARLY_DATA_SUCCESS
             || readbytes != strlen(MSG1)
             || memcmp(MSG1, buf, strlen(MSG1))) {
         printf("Failed reading early data message 1\n");
@@ -1624,10 +1624,10 @@ static int test_early_data_read_write(void)
     }
 
     /*
-     * Server should be able to write normal data, and client should be able to
+     * Server should be able to write data, and client should be able to
      * read it.
      */
-    if (!SSL_write_ex(serverssl, MSG2, strlen(MSG2), &written)
+    if (!SSL_write_early_data(serverssl, MSG2, strlen(MSG2), &written)
             || written != strlen(MSG2)) {
         printf("Failed writing message 2\n");
         goto end;
@@ -1641,23 +1641,23 @@ static int test_early_data_read_write(void)
     }
 
     /* Even after reading normal data, client should be able write early data */
-    if (!SSL_write_early(clientssl, MSG3, strlen(MSG3), &written)
+    if (!SSL_write_early_data(clientssl, MSG3, strlen(MSG3), &written)
             || written != strlen(MSG3)) {
         printf("Failed writing early data message 3\n");
         goto end;
     }
 
-    /* Server should still be able read early data after writing normal data */
-    if (SSL_read_early(serverssl, buf, sizeof(buf), &readbytes)
-                != SSL_READ_EARLY_SUCCESS
+    /* Server should still be able read early data after writing data */
+    if (SSL_read_early_data(serverssl, buf, sizeof(buf), &readbytes)
+                != SSL_READ_EARLY_DATA_SUCCESS
             || readbytes != strlen(MSG3)
             || memcmp(MSG3, buf, strlen(MSG3))) {
         printf("Failed reading early data message 3\n");
         goto end;
     }
 
-    /* Write more normal data from server and read it from client */
-    if (!SSL_write_ex(serverssl, MSG4, strlen(MSG4), &written)
+    /* Write more data from server and read it from client */
+    if (!SSL_write_early_data(serverssl, MSG4, strlen(MSG4), &written)
             || written != strlen(MSG4)) {
         printf("Failed writing message 4\n");
         goto end;
@@ -1686,8 +1686,8 @@ static int test_early_data_read_write(void)
     }
 
     /* Server should be told that there is no more early data */
-    if (SSL_read_early(serverssl, buf, sizeof(buf), &readbytes)
-                != SSL_READ_EARLY_FINISH
+    if (SSL_read_early_data(serverssl, buf, sizeof(buf), &readbytes)
+                != SSL_READ_EARLY_DATA_FINISH
             || readbytes != 0) {
         printf("Failed finishing read of early data\n");
         goto end;
@@ -1700,15 +1700,15 @@ static int test_early_data_read_write(void)
         goto end;
     }
 
-    /* Client and server should not be able to write early data now */
-    if (SSL_write_early(clientssl, MSG6, strlen(MSG6), &written)) {
+    /* Client and server should not be able to write/read early data now */
+    if (SSL_write_early_data(clientssl, MSG6, strlen(MSG6), &written)) {
         printf("Unexpected success writing early data\n");
         goto end;
     }
     ERR_clear_error();
 
-    if (SSL_read_early(serverssl, buf, sizeof(buf), &readbytes)
-                != SSL_READ_EARLY_ERROR) {
+    if (SSL_read_early_data(serverssl, buf, sizeof(buf), &readbytes)
+                != SSL_READ_EARLY_DATA_ERROR) {
         printf("Unexpected success reading early data\n");
         goto end;
     }
@@ -1745,14 +1745,14 @@ static int test_early_data_read_write(void)
     }
 
     /* Write and read some early data */
-    if (!SSL_write_early(clientssl, MSG1, strlen(MSG1), &written)
+    if (!SSL_write_early_data(clientssl, MSG1, strlen(MSG1), &written)
             || written != strlen(MSG1)) {
         printf("Failed writing early data message 1\n");
         goto end;
     }
 
-    if (SSL_read_early(serverssl, buf, sizeof(buf), &readbytes)
-                != SSL_READ_EARLY_SUCCESS
+    if (SSL_read_early_data(serverssl, buf, sizeof(buf), &readbytes)
+                != SSL_READ_EARLY_DATA_SUCCESS
             || readbytes != strlen(MSG1)
             || memcmp(MSG1, buf, strlen(MSG1))) {
         printf("Failed reading early data message 1\n");
@@ -1764,29 +1764,20 @@ static int test_early_data_read_write(void)
         goto end;
     }
 
-    /*
-     * We expect SSL_accept() to initially block as it handles the end of early
-     * data alert
-     */
-    if (SSL_accept(serverssl) > 0) {
-        printf("Unexpected success completing server handshake\n");
-        goto end;
-    }
-
     if (SSL_accept(serverssl) <= 0) {
         printf("Unable to complete server handshake\n");
         goto end;
     }
 
-    /* Client and server should not be able to write early data now */
-    if (SSL_write_early(clientssl, MSG6, strlen(MSG6), &written)) {
+    /* Client and server should not be able to write/read early data now */
+    if (SSL_write_early_data(clientssl, MSG6, strlen(MSG6), &written)) {
         printf("Unexpected success writing early data (2)\n");
         goto end;
     }
     ERR_clear_error();
 
-    if (SSL_read_early(serverssl, buf, sizeof(buf), &readbytes)
-                != SSL_READ_EARLY_ERROR) {
+    if (SSL_read_early_data(serverssl, buf, sizeof(buf), &readbytes)
+                != SSL_READ_EARLY_DATA_ERROR) {
         printf("Unexpected success reading early data (2)\n");
         goto end;
     }
@@ -1847,15 +1838,15 @@ static int test_early_data_skip(void)
     }
 
     /* Write some early data */
-    if (!SSL_write_early(clientssl, MSG1, strlen(MSG1), &written)
+    if (!SSL_write_early_data(clientssl, MSG1, strlen(MSG1), &written)
             || written != strlen(MSG1)) {
         printf("Failed writing early data message 1\n");
         goto end;
     }
 
     /* Server should reject the early data and skip over it */
-    if (SSL_read_early(serverssl, buf, sizeof(buf), &readbytes)
-                != SSL_READ_EARLY_FINISH
+    if (SSL_read_early_data(serverssl, buf, sizeof(buf), &readbytes)
+                != SSL_READ_EARLY_DATA_FINISH
             || readbytes != 0) {
         printf("Failed reading early data\n");
         goto end;
@@ -1926,8 +1917,8 @@ static int test_early_data_not_sent(void)
     }
 
     /* Server should detect that early data has not been sent */
-    if (SSL_read_early(serverssl, buf, sizeof(buf), &readbytes)
-                != SSL_READ_EARLY_FINISH
+    if (SSL_read_early_data(serverssl, buf, sizeof(buf), &readbytes)
+                != SSL_READ_EARLY_DATA_FINISH
             || readbytes != 0) {
         printf("Failed reading early data\n");
         goto end;
@@ -2008,7 +1999,7 @@ static int test_early_data_not_expected(void)
         goto end;
 
     /* Write some early data */
-    if (!SSL_write_early(clientssl, MSG1, strlen(MSG1), &written)) {
+    if (!SSL_write_early_data(clientssl, MSG1, strlen(MSG1), &written)) {
         printf("Unexpected failure writing message 1\n");
         goto end;
     }
@@ -2106,11 +2097,11 @@ static int test_early_data_tls1_2(void)
 
     /*
      * Server should do TLSv1.2 handshake. First it will block waiting for more
-     * messages from client after ServerDone. Then SSL_read_early should finish
-     * and detect that early data has not been sent
+     * messages from client after ServerDone. Then SSL_read_early_data should
+     * finish and detect that early data has not been sent
      */
-    if (SSL_read_early(serverssl, buf, sizeof(buf), &readbytes)
-                != SSL_READ_EARLY_ERROR) {
+    if (SSL_read_early_data(serverssl, buf, sizeof(buf), &readbytes)
+                != SSL_READ_EARLY_DATA_ERROR) {
         printf("Unexpected success reading early data\n");
         goto end;
     }
@@ -2124,8 +2115,8 @@ static int test_early_data_tls1_2(void)
         goto end;
     }
 
-    if (SSL_read_early(serverssl, buf, sizeof(buf), &readbytes)
-                != SSL_READ_EARLY_FINISH
+    if (SSL_read_early_data(serverssl, buf, sizeof(buf), &readbytes)
+                != SSL_READ_EARLY_DATA_FINISH
             || readbytes != 0) {
         printf("Failed reading early data\n");
         goto end;