Skip to content

Commit b2c105d

Browse files
authored
Merge pull request #9292 from embhorn/zd20626
Fix GCC warnings
2 parents 6fbd101 + dd22fa3 commit b2c105d

7 files changed

Lines changed: 58 additions & 19 deletions

File tree

src/internal.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25907,16 +25907,7 @@ int SendData(WOLFSSL* ssl, const void* data, size_t sz)
2590725907
}
2590825908
#endif /* WOLFSSL_DTLS13 */
2590925909

25910-
#ifdef WOLFSSL_DTLS
25911-
if (ssl->options.dtls) {
25912-
buffSz = wolfSSL_GetMaxFragSize(ssl, (word32)sz - sent);
25913-
}
25914-
else
25915-
#endif
25916-
{
25917-
buffSz = wolfSSL_GetMaxFragSize(ssl, (word32)sz - sent);
25918-
25919-
}
25910+
buffSz = wolfSSL_GetMaxFragSize(ssl, (word32)sz - sent);
2592025911

2592125912
if (sent == (word32)sz) break;
2592225913

src/pk.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,13 @@ static int wolfssl_print_indent(WOLFSSL_BIO* bio, char* line, int lineLen,
724724
int ret = 1;
725725

726726
if (indent > 0) {
727+
int len_wanted;
728+
/* Cap indent to buffer size to avoid format truncation warning */
729+
if (indent >= lineLen) {
730+
indent = lineLen - 1;
731+
}
727732
/* Print indent spaces. */
728-
int len_wanted = XSNPRINTF(line, (size_t)lineLen, "%*s", indent, " ");
733+
len_wanted = XSNPRINTF(line, (size_t)lineLen, "%*s", indent, " ");
729734
if ((len_wanted < 0) || (len_wanted >= lineLen)) {
730735
WOLFSSL_ERROR_MSG("Buffer overflow formatting indentation");
731736
ret = 0;

src/ssl_bn.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,8 @@ int wolfSSL_BN_cmp(const WOLFSSL_BIGNUM* a, const WOLFSSL_BIGNUM* b)
11261126
ret = 1;
11271127
}
11281128
else {
1129+
PRAGMA_GCC_DIAG_PUSH
1130+
PRAGMA_GCC("GCC diagnostic ignored \"-Wduplicated-branches\"")
11291131
/* Compare big numbers with wolfCrypt. */
11301132
ret = mp_cmp((mp_int*)a->internal, (mp_int*)b->internal);
11311133
/* Convert wolfCrypt return value. */
@@ -1139,8 +1141,11 @@ int wolfSSL_BN_cmp(const WOLFSSL_BIGNUM* a, const WOLFSSL_BIGNUM* b)
11391141
ret = -1;
11401142
}
11411143
else {
1144+
/* ignored warning here because the same return value
1145+
was intentional */
11421146
ret = WOLFSSL_FATAL_ERROR; /* also -1 */
11431147
}
1148+
PRAGMA_GCC_DIAG_POP
11441149
}
11451150

11461151
return ret;

src/tls.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5310,9 +5310,14 @@ int TLSX_SupportedFFDHE_Set(WOLFSSL* ssl)
53105310
SupportedCurve* serverGroup;
53115311

53125312
ext = TLSX_Find(priority, TLSX_SUPPORTED_GROUPS);
5313-
serverGroup = (SupportedCurve*)ext->data;
5314-
5315-
ret = tlsx_ffdhe_find_group(ssl, clientGroup, serverGroup);
5313+
if (ext == NULL) {
5314+
WOLFSSL_MSG("Could not find supported groups extension");
5315+
ret = 0;
5316+
}
5317+
else {
5318+
serverGroup = (SupportedCurve*)ext->data;
5319+
ret = tlsx_ffdhe_find_group(ssl, clientGroup, serverGroup);
5320+
}
53165321
}
53175322

53185323
TLSX_FreeAll(priority, ssl->heap);

src/x509.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,12 @@ static WOLFSSL_ASN1_STRING* wolfSSL_X509_EXTENSION_get_data_internal(
14161416

14171417

14181418
#ifndef NO_BIO
1419+
1420+
#ifndef MAX_INDENT
1421+
#define MAX_INDENT 40
1422+
#endif
1423+
1424+
14191425
/* Return 0 on success and 1 on failure. Copies ext data to bio, using indent
14201426
* to pad the output. flag is ignored. */
14211427
int wolfSSL_X509V3_EXT_print(WOLFSSL_BIO *out, WOLFSSL_X509_EXTENSION *ext,
@@ -1430,6 +1436,9 @@ int wolfSSL_X509V3_EXT_print(WOLFSSL_BIO *out, WOLFSSL_X509_EXTENSION *ext,
14301436
int tmpLen = 0;
14311437
WOLFSSL_ENTER("wolfSSL_X509V3_EXT_print");
14321438

1439+
if (indent < 0) indent = 0;
1440+
if (indent > MAX_INDENT) indent = MAX_INDENT;
1441+
14331442
if ((out == NULL) || (ext == NULL)) {
14341443
WOLFSSL_MSG("NULL parameter error");
14351444
return rc;
@@ -6223,6 +6232,9 @@ static int X509PrintKeyUsage(WOLFSSL_BIO* bio, WOLFSSL_X509* x509, int indent)
62236232
"Decipher Only"
62246233
};
62256234

6235+
if (indent < 0) indent = 0;
6236+
if (indent > MAX_INDENT) indent = MAX_INDENT;
6237+
62266238
if (bio == NULL || x509 == NULL) {
62276239
ret = WOLFSSL_FAILURE;
62286240
}
@@ -6394,6 +6406,9 @@ static int X509PrintSerial(WOLFSSL_BIO* bio, WOLFSSL_X509* x509, int indent)
63946406
unsigned char serial[32];
63956407
int sz = sizeof(serial);
63966408

6409+
if (indent < 0) indent = 0;
6410+
if (indent > MAX_INDENT) indent = MAX_INDENT;
6411+
63976412
XMEMSET(serial, 0, sz);
63986413
if (wolfSSL_X509_get_serial_number(x509, serial, &sz) == WOLFSSL_SUCCESS) {
63996414
X509PrintSerial_ex(bio, serial, sz, 1, indent);
@@ -6486,6 +6501,9 @@ static int X509PrintExtensions(WOLFSSL_BIO* bio, WOLFSSL_X509* x509, int indent)
64866501
int count, i;
64876502
char* buf = NULL;
64886503

6504+
if (indent < 0) indent = 0;
6505+
if (indent > MAX_INDENT) indent = MAX_INDENT;
6506+
64896507
count = wolfSSL_X509_get_ext_count(x509);
64906508
if (count <= 0)
64916509
return WOLFSSL_SUCCESS;
@@ -6899,6 +6917,9 @@ static int X509PrintPubKey(WOLFSSL_BIO* bio, WOLFSSL_X509* x509, int indent)
68996917
int len;
69006918
int ret = WOLFSSL_SUCCESS;
69016919

6920+
if (indent < 0) indent = 0;
6921+
if (indent > MAX_INDENT) indent = MAX_INDENT;
6922+
69026923
if (bio == NULL || x509 == NULL)
69036924
return BAD_FUNC_ARG;
69046925

@@ -6986,6 +7007,9 @@ static int X509PrintVersion(WOLFSSL_BIO* bio, int version, int indent)
69867007
char scratch[MAX_WIDTH];
69877008
int scratchLen;
69887009

7010+
if (indent < 0) indent = 0;
7011+
if (indent > MAX_INDENT) indent = MAX_INDENT;
7012+
69897013
scratchLen = XSNPRINTF(scratch, MAX_WIDTH, "%*s%s", indent, "", "Version:");
69907014
if ((scratchLen < 0) || (scratchLen >= MAX_WIDTH)) {
69917015
return WOLFSSL_FAILURE;
@@ -7019,6 +7043,9 @@ static int X509PrintReqAttributes(WOLFSSL_BIO* bio, WOLFSSL_X509* x509,
70197043
int scratchLen;
70207044
int i = 0;
70217045

7046+
if (indent < 0) indent = 0;
7047+
if (indent > MAX_INDENT) indent = MAX_INDENT;
7048+
70227049
if ((scratchLen = XSNPRINTF(scratch, MAX_WIDTH,
70237050
"%*s%s", indent, "", "Attributes: \n"))
70247051
>= MAX_WIDTH)
@@ -8746,6 +8773,9 @@ static int X509RevokedPrintSerial(WOLFSSL_BIO* bio, RevokedCert* rev,
87468773
unsigned char serial[32];
87478774
int sz = sizeof(serial);
87488775

8776+
if (indent < 0) indent = 0;
8777+
if (indent > MAX_INDENT) indent = MAX_INDENT;
8778+
87498779
XMEMSET(serial, 0, sz);
87508780
if (wolfSSL_X509_REVOKED_get_serial_number(rev, serial, &sz)
87518781
== WOLFSSL_SUCCESS) {
@@ -8807,6 +8837,9 @@ static int X509CRLPrintExtensions(WOLFSSL_BIO* bio, WOLFSSL_X509_CRL* crl,
88078837
char tmp[MAX_WIDTH]; /* buffer for XSNPRINTF */
88088838
int ret = 0;
88098839

8840+
if (indent < 0) indent = 0;
8841+
if (indent > MAX_INDENT) indent = MAX_INDENT;
8842+
88108843
if (XSNPRINTF(tmp, MAX_WIDTH, "%*s%s\n", indent, "",
88118844
"CRL extensions:") >= MAX_WIDTH) {
88128845
ret = WOLFSSL_FAILURE;

wolfcrypt/src/evp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6810,7 +6810,7 @@ void wolfSSL_EVP_init(void)
68106810
}
68116811

68126812
static int EvpCipherAesGCM(WOLFSSL_EVP_CIPHER_CTX* ctx, byte* dst,
6813-
byte* src, word32 len)
6813+
const byte* src, word32 len)
68146814
{
68156815
int ret = WC_NO_ERR_TRACE(WOLFSSL_FAILURE);
68166816

@@ -7002,7 +7002,7 @@ void wolfSSL_EVP_init(void)
70027002
}
70037003

70047004
static int EvpCipherAesCCM(WOLFSSL_EVP_CIPHER_CTX* ctx, byte* dst,
7005-
byte* src, word32 len)
7005+
const byte* src, word32 len)
70067006
{
70077007
int ret = WC_NO_ERR_TRACE(WOLFSSL_FAILURE);
70087008

@@ -8507,8 +8507,8 @@ void wolfSSL_EVP_init(void)
85078507
}
85088508

85098509
/* Return length on ok */
8510-
int wolfSSL_EVP_Cipher(WOLFSSL_EVP_CIPHER_CTX* ctx, byte* dst, byte* src,
8511-
word32 len)
8510+
int wolfSSL_EVP_Cipher(WOLFSSL_EVP_CIPHER_CTX* ctx, byte* dst,
8511+
const byte* src, word32 len)
85128512
{
85138513
int ret = WC_NO_ERR_TRACE(WOLFSSL_FAILURE);
85148514

wolfssl/openssl/evp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ WOLFSSL_API int wolfSSL_EVP_CIPHER_CTX_set_iv(WOLFSSL_EVP_CIPHER_CTX* ctx, byte
892892
WOLFSSL_API int wolfSSL_EVP_CIPHER_CTX_get_iv(WOLFSSL_EVP_CIPHER_CTX* ctx, byte* iv,
893893
int ivLen);
894894
WOLFSSL_API int wolfSSL_EVP_Cipher(WOLFSSL_EVP_CIPHER_CTX* ctx,
895-
unsigned char* dst, unsigned char* src,
895+
unsigned char* dst, const unsigned char* src,
896896
unsigned int len);
897897

898898
WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_get_cipherbynid(int id);

0 commit comments

Comments
 (0)