Skip to content

Commit e47be21

Browse files
committed
Fix buffer warnings in x509
1 parent f713cdb commit e47be21

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

src/ssl_bn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ int wolfSSL_BN_cmp(const WOLFSSL_BIGNUM* a, const WOLFSSL_BIGNUM* b)
11531153
else {
11541154
PRAGMA_GCC_DIAG_PUSH
11551155
PRAGMA_GCC("GCC diagnostic ignored \"-Werror=duplicated-branches\"")
1156-
/* ignored warning here because the same return value
1156+
/* ignored warning here because the same return value
11571157
was intentional */
11581158
ret = WOLFSSL_FATAL_ERROR; /* also -1 */
11591159
PRAGMA_GCC_DIAG_POP

src/x509.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,12 @@ static WOLFSSL_ASN1_STRING* wolfSSL_X509_EXTENSION_get_data_internal(
14741474

14751475

14761476
#ifndef NO_BIO
1477+
1478+
#ifndef MAX_INDENT
1479+
#define MAX_INDENT 40
1480+
#endif
1481+
1482+
14771483
/* Return 0 on success and 1 on failure. Copies ext data to bio, using indent
14781484
* to pad the output. flag is ignored. */
14791485
int wolfSSL_X509V3_EXT_print(WOLFSSL_BIO *out, WOLFSSL_X509_EXTENSION *ext,
@@ -1488,6 +1494,9 @@ int wolfSSL_X509V3_EXT_print(WOLFSSL_BIO *out, WOLFSSL_X509_EXTENSION *ext,
14881494
int tmpLen = 0;
14891495
WOLFSSL_ENTER("wolfSSL_X509V3_EXT_print");
14901496

1497+
if (indent < 0) indent = 0;
1498+
if (indent > MAX_INDENT) indent = MAX_INDENT;
1499+
14911500
if ((out == NULL) || (ext == NULL)) {
14921501
WOLFSSL_MSG("NULL parameter error");
14931502
return rc;
@@ -6320,6 +6329,9 @@ static int X509PrintKeyUsage(WOLFSSL_BIO* bio, WOLFSSL_X509* x509, int indent)
63206329
"Decipher Only"
63216330
};
63226331

6332+
if (indent < 0) indent = 0;
6333+
if (indent > MAX_INDENT) indent = MAX_INDENT;
6334+
63236335
if (bio == NULL || x509 == NULL) {
63246336
ret = WOLFSSL_FAILURE;
63256337
}
@@ -6491,6 +6503,9 @@ static int X509PrintSerial(WOLFSSL_BIO* bio, WOLFSSL_X509* x509, int indent)
64916503
unsigned char serial[32];
64926504
int sz = sizeof(serial);
64936505

6506+
if (indent < 0) indent = 0;
6507+
if (indent > MAX_INDENT) indent = MAX_INDENT;
6508+
64946509
XMEMSET(serial, 0, sz);
64956510
if (wolfSSL_X509_get_serial_number(x509, serial, &sz) == WOLFSSL_SUCCESS) {
64966511
X509PrintSerial_ex(bio, serial, sz, 1, indent);
@@ -6583,6 +6598,9 @@ static int X509PrintExtensions(WOLFSSL_BIO* bio, WOLFSSL_X509* x509, int indent)
65836598
int count, i;
65846599
char* buf = NULL;
65856600

6601+
if (indent < 0) indent = 0;
6602+
if (indent > MAX_INDENT) indent = MAX_INDENT;
6603+
65866604
count = wolfSSL_X509_get_ext_count(x509);
65876605
if (count <= 0)
65886606
return WOLFSSL_SUCCESS;
@@ -6996,6 +7014,9 @@ static int X509PrintPubKey(WOLFSSL_BIO* bio, WOLFSSL_X509* x509, int indent)
69967014
int len;
69977015
int ret = WOLFSSL_SUCCESS;
69987016

7017+
if (indent < 0) indent = 0;
7018+
if (indent > MAX_INDENT) indent = MAX_INDENT;
7019+
69997020
if (bio == NULL || x509 == NULL)
70007021
return BAD_FUNC_ARG;
70017022

@@ -7083,6 +7104,9 @@ static int X509PrintVersion(WOLFSSL_BIO* bio, int version, int indent)
70837104
char scratch[MAX_WIDTH];
70847105
int scratchLen;
70857106

7107+
if (indent < 0) indent = 0;
7108+
if (indent > MAX_INDENT) indent = MAX_INDENT;
7109+
70867110
scratchLen = XSNPRINTF(scratch, MAX_WIDTH, "%*s%s", indent, "", "Version:");
70877111
if ((scratchLen < 0) || (scratchLen >= MAX_WIDTH)) {
70887112
return WOLFSSL_FAILURE;
@@ -7116,6 +7140,9 @@ static int X509PrintReqAttributes(WOLFSSL_BIO* bio, WOLFSSL_X509* x509,
71167140
int scratchLen;
71177141
int i = 0;
71187142

7143+
if (indent < 0) indent = 0;
7144+
if (indent > MAX_INDENT) indent = MAX_INDENT;
7145+
71197146
if ((scratchLen = XSNPRINTF(scratch, MAX_WIDTH,
71207147
"%*s%s", indent, "", "Attributes: \n"))
71217148
>= MAX_WIDTH)
@@ -8863,6 +8890,9 @@ static int X509RevokedPrintSerial(WOLFSSL_BIO* bio, RevokedCert* rev,
88638890
unsigned char serial[32];
88648891
int sz = sizeof(serial);
88658892

8893+
if (indent < 0) indent = 0;
8894+
if (indent > MAX_INDENT) indent = MAX_INDENT;
8895+
88668896
XMEMSET(serial, 0, sz);
88678897
if (wolfSSL_X509_REVOKED_get_serial_number(rev, serial, &sz)
88688898
== WOLFSSL_SUCCESS) {
@@ -8921,9 +8951,12 @@ static int X509CRLPrintSignature(WOLFSSL_BIO* bio, WOLFSSL_X509_CRL* crl,
89218951
static int X509CRLPrintExtensions(WOLFSSL_BIO* bio, WOLFSSL_X509_CRL* crl,
89228952
int indent)
89238953
{
8924-
char tmp[MAX_WIDTH]; /* buffer for XSNPRINTF */
8954+
char tmp[MAX_WIDTH];
89258955
int ret = 0;
89268956

8957+
if (indent < 0) indent = 0;
8958+
if (indent > MAX_INDENT) indent = MAX_INDENT;
8959+
89278960
if (XSNPRINTF(tmp, MAX_WIDTH, "%*s%s\n", indent, "",
89288961
"CRL extensions:") >= MAX_WIDTH) {
89298962
ret = WOLFSSL_FAILURE;

0 commit comments

Comments
 (0)