F-1698 F-1699 F-2094 F-2097 F-3222 F-3465 F-3900 F-4130 F-4599 F-5611 F-6285: fix logic and conditional bugs

pull/318/merge
Emma Stensland 2026-06-30 14:24:39 -06:00 committed by Paul Adelsbach
parent a627f04342
commit ac4b7b574e
11 changed files with 32 additions and 30 deletions

View File

@ -51,8 +51,9 @@ int main(int argc, char *argv[])
int input;
char reply[RECV_MSG_LEN];
memset(reply, 0, RECV_MSG_LEN);
input = wolfSSL_read(ssl, reply, RECV_MSG_LEN);
input = wolfSSL_read(ssl, reply, RECV_MSG_LEN - 1);
if (input > 0) {
reply[input] = '\0';
printf("Got message: %s\n", reply);
}
}

View File

@ -141,7 +141,7 @@ int main(int argc, char** argv)
/* First call to get required buffer size */
ret = wolfSSL_dtls_export(ssl, NULL, &sessionSz);
if (ret != 0 && sessionSz == 0) {
if (ret < 0 || sessionSz == 0) {
fprintf(stderr, "Error: wolfSSL_dtls_export (get size) failed: %d\n",
ret);
ret = 1;

View File

@ -148,6 +148,12 @@ main(int argc,
return EXIT_FAILURE;
}
ret = talk_to_server(ssl_res, "client message after resume");
if (ret) {
return EXIT_FAILURE;
}
/* Test if the resume was successful */
if (wolfSSL_session_reused(ssl_res)) {
printf("info: session ID reused; Successful resume\n");
@ -156,12 +162,6 @@ main(int argc,
printf("info: session ID not reused\n");
}
ret = talk_to_server(ssl_res, "client message after resume");
if (ret) {
return EXIT_FAILURE;
}
/* Cleanup memory used for storing the session information */
wolfSSL_shutdown(ssl_res);
wolfSSL_free(ssl_res);

View File

@ -463,8 +463,8 @@ WOLFSSL* newSSL(WOLFSSL_CTX* ctx, int fd, WC_RNG* rng, struct ConnList* connList
/* Check that the CID is not in use */
for (conn = connList; conn != NULL; conn = conn->next) {
byte* cid = NULL;
if (wolfSSL_dtls_cid_get0_rx(ssl, &cid) == WOLFSSL_SUCCESS &&
memcmp(newCid, cid, CID_SIZE) == 0) {
if (wolfSSL_dtls_cid_get0_rx(conn->ssl, &cid) == WOLFSSL_SUCCESS &&
cid != NULL && memcmp(newCid, cid, CID_SIZE) == 0) {
found = 1;
break;
}

View File

@ -210,7 +210,7 @@ int main(int argc, char** argv)
/* First call to get required buffer size */
ret = wolfSSL_dtls_export(ssl, NULL, &sessionSz);
if (ret != 0 && sessionSz == 0) {
if (ret < 0 || sessionSz == 0) {
fprintf(stderr, "Error: wolfSSL_dtls_export (get size) failed: %d\n",
ret);
ret = 1;

View File

@ -99,7 +99,7 @@ enum wc_HashType hash_type_from_string(char* name)
#endif
#ifdef WOLFSSL_SM3
else if (strcmp(name, "SM3") == 0) {
return WC_HASH_TYPE_SHAKE256;
return WC_HASH_TYPE_SM3;
}
#endif
else {

View File

@ -101,11 +101,11 @@ static int load_certs(byte* cert, word32* certSz, byte* key, word32* keySz)
}
static size_t envelopedData_encrypt(byte* cert, word32 certSz, byte* key,
static int envelopedData_encrypt(byte* cert, word32 certSz, byte* key,
word32 keySz, byte* out, word32 outSz,
word32 contentSz, byte useStreamMode)
{
size_t ret;
int ret;
PKCS7* pkcs7;
pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
@ -125,7 +125,7 @@ static size_t envelopedData_encrypt(byte* cert, word32 certSz, byte* key,
/* add recipient using RSA certificate (KTRI type) */
ret = wc_PKCS7_AddRecipient_KTRI(pkcs7, cert, certSz, 0);
if (ret < 0) {
printf("wc_PKCS7_AddRecipient_KTRI() failed, ret = %zu\n", ret);
printf("wc_PKCS7_AddRecipient_KTRI() failed, ret = %d\n", ret);
wc_PKCS7_Free(pkcs7);
return -1;
}
@ -133,7 +133,7 @@ static size_t envelopedData_encrypt(byte* cert, word32 certSz, byte* key,
/* encode envelopedData, returns size */
ret = wc_PKCS7_EncodeEnvelopedData(pkcs7, out, outSz);
if (ret <= 0) {
printf("ERROR: wc_PKCS7_EncodeEnvelopedData() failed, ret = %zu\n", ret);
printf("ERROR: wc_PKCS7_EncodeEnvelopedData() failed, ret = %d\n", ret);
wc_PKCS7_Free(pkcs7);
return -1;
@ -147,11 +147,11 @@ static size_t envelopedData_encrypt(byte* cert, word32 certSz, byte* key,
return ret;
}
static size_t envelopedData_decrypt(byte* in, word32 inSz, byte* cert,
static int envelopedData_decrypt(byte* in, word32 inSz, byte* cert,
word32 certSz, byte* key, word32 keySz,
byte* out, word32 outSz)
{
size_t ret;
int ret;
PKCS7* pkcs7;
pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
@ -175,7 +175,7 @@ static size_t envelopedData_decrypt(byte* in, word32 inSz, byte* cert,
/* decode envelopedData, returns size */
ret = wc_PKCS7_DecodeEnvelopedData(pkcs7, in, inSz, out, outSz);
if (ret <= 0) {
printf("Failed to decode EnvelopedData bundle (%s), error %zu\n",
printf("Failed to decode EnvelopedData bundle (%s), error %d\n",
encodedFileKTRI, ret);
wc_PKCS7_Free(pkcs7);
return -1;
@ -197,7 +197,7 @@ static size_t envelopedData_decrypt(byte* in, word32 inSz, byte* cert,
int main(int argc, char** argv)
{
int ret = 0;
size_t encryptedSz = 0, decryptedSz;
int encryptedSz = 0, decryptedSz;
word32 certSz, keySz, contentSz = 0;
byte cert[DEFAULT_EXAMPLE_BUFFER_SIZE];
@ -279,7 +279,7 @@ int main(int argc, char** argv)
printf("error reading file %s\n", encodedFileKTRI);
ret = -1;
}
printf("Read %ld bytes for encrypted file found\n", encryptedSz);
printf("Read %d bytes for encrypted file found\n", encryptedSz);
}
if (ret == 0) {

View File

@ -176,6 +176,7 @@ static int ReadSmimeAndCert(char* smimeFile, char* certFile, char* contentFile,
{
int ret;
XFILE f;
int contentMaxSz = *contentSz;
*contentSz = 0;
f = XFOPEN(smimeFile, "rb");
@ -227,10 +228,10 @@ static int ReadSmimeAndCert(char* smimeFile, char* certFile, char* contentFile,
return -1;
}
else {
ret = XFREAD(content, 1, *contentSz, f);
ret = XFREAD(content, 1, contentMaxSz, f);
if (ret >= 0) {
if (ret == *contentSz) {
printf("Cert read in was larger than buffer\n");
if (ret == contentMaxSz) {
printf("Content read in was larger than buffer\n");
XFCLOSE(f);
return -1;
}

View File

@ -261,7 +261,7 @@ do_xmss_example(const char * params,
}
ret = wc_XmssKey_GetPrivLen(&signingKey, &privSz);
if (ret || pubSz == 0) {
if (ret || privSz == 0) {
fprintf(stderr, "error: wc_XmssKey_GetPrivLen returned: %d, %d\n",
ret, privSz);
goto exit_xmss_example;

View File

@ -350,13 +350,13 @@ int main()
}
/* closes the connections after responding */
wolfSSL_shutdown(ssl);
wolfSSL_free(ssl);
ssl = NULL;
if (close(connfd) == -1) {
printf("Fatal error : close error\n");
return 1;
}
wolfSSL_shutdown(ssl);
wolfSSL_free(ssl);
ssl = NULL;
}
}

View File

@ -254,8 +254,8 @@ int main(int argc, char** argv)
err = wolfSSL_get_error(ssl, 0);
if (err == WOLFSSL_ERROR_WANT_READ)
tcp_select(sockfd, SELECT_WAIT_SEC, 1);
} while (ret == WOLFSSL_ERROR_WANT_READ ||
ret == WOLFSSL_ERROR_WANT_WRITE);
} while (err == WOLFSSL_ERROR_WANT_READ ||
err == WOLFSSL_ERROR_WANT_WRITE);
printf("Shutdown complete\n");
ret = 0;