Replace some unsafe usage of strncpy

Ensure everything is null terminated
This commit is contained in:
TingPing 2014-09-20 13:52:31 -04:00 committed by TingPing
parent 0495a79fc2
commit ed9a984786

View File

@ -113,8 +113,8 @@ ASN1_TIME_snprintf (char *buf, int buf_len, ASN1_TIME * tm)
buf[0] = 0; buf[0] = 0;
if (expires != NULL) if (expires != NULL)
{ {
memset (buf, 0, buf_len); /* expires is not \0 terminated */
strncpy (buf, expires, 24); safe_strcpy (buf, expires, MIN(24, buf_len));
} }
BIO_free (inMem); BIO_free (inMem);
} }
@ -176,17 +176,17 @@ _SSL_get_cert_info (struct cert_info *cert_info, SSL * ssl)
peer_pkey = X509_get_pubkey (peer_cert); peer_pkey = X509_get_pubkey (peer_cert);
strncpy (cert_info->algorithm, safe_strcpy (cert_info->algorithm,
(alg == NID_undef) ? "Unknown" : OBJ_nid2ln (alg), (alg == NID_undef) ? "Unknown" : OBJ_nid2ln (alg),
sizeof (cert_info->algorithm)); sizeof (cert_info->algorithm));
cert_info->algorithm_bits = EVP_PKEY_bits (peer_pkey); cert_info->algorithm_bits = EVP_PKEY_bits (peer_pkey);
strncpy (cert_info->sign_algorithm, safe_strcpy (cert_info->sign_algorithm,
(sign_alg == NID_undef) ? "Unknown" : OBJ_nid2ln (sign_alg), (sign_alg == NID_undef) ? "Unknown" : OBJ_nid2ln (sign_alg),
sizeof (cert_info->sign_algorithm)); sizeof (cert_info->sign_algorithm));
/* EVP_PKEY_bits(ca_pkey)); */ /* EVP_PKEY_bits(ca_pkey)); */
cert_info->sign_algorithm_bits = 0; cert_info->sign_algorithm_bits = 0;
strncpy (cert_info->notbefore, notBefore, sizeof (cert_info->notbefore)); safe_strcpy (cert_info->notbefore, notBefore, sizeof (cert_info->notbefore));
strncpy (cert_info->notafter, notAfter, sizeof (cert_info->notafter)); safe_strcpy (cert_info->notafter, notAfter, sizeof (cert_info->notafter));
EVP_PKEY_free (peer_pkey); EVP_PKEY_free (peer_pkey);
@ -215,9 +215,9 @@ _SSL_get_cipher_info (SSL * ssl)
c = SSL_get_current_cipher (ssl); c = SSL_get_current_cipher (ssl);
strncpy (chiper_info.version, SSL_CIPHER_get_version (c), safe_strcpy (chiper_info.version, SSL_CIPHER_get_version (c),
sizeof (chiper_info.version)); sizeof (chiper_info.version));
strncpy (chiper_info.chiper, SSL_CIPHER_get_name (c), safe_strcpy (chiper_info.chiper, SSL_CIPHER_get_name (c),
sizeof (chiper_info.chiper)); sizeof (chiper_info.chiper));
SSL_CIPHER_get_bits (c, &chiper_info.chiper_bits); SSL_CIPHER_get_bits (c, &chiper_info.chiper_bits);