@@ -3599,9 +3599,8 @@ char* wolfSSL_X509_get_name_oneline(WOLFSSL_X509_NAME* name, char* in, int sz)
35993599 WOLFSSL_MSG ("Memory error" );
36003600 return NULL ;
36013601 }
3602- if ((strLen = XSNPRINTF (str , (size_t )strSz , "%s=%s, " , sn , buf ))
3603- >= strSz )
3604- {
3602+ strLen = XSNPRINTF (str , (size_t )strSz , "%s=%s, " , sn , buf );
3603+ if ((strLen < 0 ) || (strLen >= strSz )) {
36053604 WOLFSSL_MSG ("buffer overrun" );
36063605 XFREE (str , NULL , DYNAMIC_TYPE_TMP_BUFFER );
36073606 return NULL ;
@@ -3617,8 +3616,8 @@ char* wolfSSL_X509_get_name_oneline(WOLFSSL_X509_NAME* name, char* in, int sz)
36173616 WOLFSSL_MSG ("Memory error" );
36183617 return NULL ;
36193618 }
3620- if (( strLen = XSNPRINTF (str , (size_t )strSz , "%s=%s" , sn ,
3621- buf )) >= strSz ) {
3619+ strLen = XSNPRINTF (str , (size_t )strSz , "%s=%s" , sn , buf );
3620+ if (( strLen < 0 ) || ( strLen >= strSz ) ) {
36223621 WOLFSSL_MSG ("buffer overrun" );
36233622 XFREE (str , NULL , DYNAMIC_TYPE_TMP_BUFFER );
36243623 return NULL ;
@@ -6971,7 +6970,7 @@ static int X509PrintPubKey(WOLFSSL_BIO* bio, WOLFSSL_X509* x509, int indent)
69716970 case ECDSAk :
69726971 len = XSNPRINTF (scratch , MAX_WIDTH ,
69736972 "%*sPublic Key Algorithm: EC\n" , indent + 4 , "" );
6974- if (len >= MAX_WIDTH )
6973+ if (( len < 0 ) || ( len >= MAX_WIDTH ) )
69756974 return WOLFSSL_FAILURE ;
69766975 if (wolfSSL_BIO_write (bio , scratch , len ) <= 0 )
69776976 return WOLFSSL_FAILURE ;
@@ -7033,22 +7032,21 @@ static int X509PrintVersion(WOLFSSL_BIO* bio, int version, int indent)
70337032 char scratch [MAX_WIDTH ];
70347033 int scratchLen ;
70357034
7036- if ((scratchLen = XSNPRINTF (scratch , MAX_WIDTH ,
7037- "%*s%s" , indent , "" , "Version:" ))
7038- >= MAX_WIDTH )
7039- {
7035+ scratchLen = XSNPRINTF (scratch , MAX_WIDTH , "%*s%s" , indent , "" , "Version:" );
7036+ if ((scratchLen < 0 ) || (scratchLen >= MAX_WIDTH )) {
70407037 return WOLFSSL_FAILURE ;
70417038 }
7039+
70427040 if (wolfSSL_BIO_write (bio , scratch , scratchLen ) <= 0 ) {
70437041 return WOLFSSL_FAILURE ;
70447042 }
70457043
7046- if ((scratchLen = XSNPRINTF (scratch , MAX_WIDTH ,
7047- " %d (0x%x)\n" , version , (byte )version - 1 ))
7048- >= MAX_WIDTH )
7049- {
7044+ scratchLen = XSNPRINTF (scratch , MAX_WIDTH , " %d (0x%x)\n" ,
7045+ version , (byte )version - 1 );
7046+ if ((scratchLen < 0 ) || (scratchLen >= MAX_WIDTH )) {
70507047 return WOLFSSL_FAILURE ;
70517048 }
7049+
70527050 if (wolfSSL_BIO_write (bio , scratch , scratchLen ) <= 0 ) {
70537051 return WOLFSSL_FAILURE ;
70547052 }
@@ -8064,6 +8062,7 @@ int wc_GeneratePreTBS(DecodedCert* cert, byte *der, int derSz) {
80648062
80658063 if (x != NULL ) {
80668064 wolfSSL_X509_free (x );
8065+ x = NULL ;
80678066 }
80688067
80698068 return ret ;
0 commit comments