8301274: update for deprecated sprintf for security components

Reviewed-by: ascarpino
This commit is contained in:
Xue-Lei Andrew Fan 2023-02-14 15:37:47 +00:00
parent ec901f28c3
commit f7dee77d73

View File

@ -1223,17 +1223,17 @@ JNIEXPORT jboolean JNICALL Java_sun_security_mscapi_CSignature_verifyCngSignedHa
#define DUMP_PROP(p) \
if (::NCryptGetProperty(hKey, p, (PBYTE)buffer, 8192, &len, NCRYPT_SILENT_FLAG) == ERROR_SUCCESS) { \
sprintf(header, "%s %ls", #p, p); \
snprintf(header, sizeof(header), "%s %ls", #p, p); \
dump(header, buffer, len); \
}
#define EXPORT_BLOB(p) \
desc.cBuffers = 0; \
if (::NCryptExportKey(hKey, NULL, p, &desc, (PBYTE)buffer, 8192, &len, NCRYPT_SILENT_FLAG) == ERROR_SUCCESS) { \
sprintf(header, "%s %ls (%ld)", #p, p, desc.cBuffers); \
snprintf(header, sizeof(header), "%s %ls (%ld)", #p, p, desc.cBuffers); \
dump(header, buffer, len); \
for (int i = 0; i < (int)desc.cBuffers; i++) { \
sprintf(header, "desc %ld", desc.pBuffers[i].BufferType); \
snprintf(header, sizeof(header), "desc %ld", desc.pBuffers[i].BufferType); \
dump(header, (PBYTE)desc.pBuffers[i].pvBuffer, desc.pBuffers[i].cbBuffer); \
} \
}
@ -1310,7 +1310,7 @@ void showProperty(NCRYPT_HANDLE hKey) {
bbd.pBuffers = &bb;
if(::NCryptExportKey(hKey, NULL, NCRYPT_PKCS8_PRIVATE_KEY_BLOB, NULL,
(PBYTE)buffer, 8192, &len, NCRYPT_SILENT_FLAG) == ERROR_SUCCESS) {
sprintf(header, "NCRYPT_PKCS8_PRIVATE_KEY_BLOB %ls", NCRYPT_PKCS8_PRIVATE_KEY_BLOB);
snprintf(header, sizeof(header), "NCRYPT_PKCS8_PRIVATE_KEY_BLOB %ls", NCRYPT_PKCS8_PRIVATE_KEY_BLOB);
dump(header, buffer, len);
}
EXPORT_BLOB(NCRYPT_PROTECTED_KEY_BLOB);
@ -1445,7 +1445,7 @@ JNIEXPORT jstring JNICALL Java_sun_security_mscapi_CKey_getKeyType
} else {
char buffer[64];
if (sprintf(buffer, "%lu", dwAlgId)) {
if (snprintf(buffer, sizeof(buffer), "%lu", dwAlgId)) {
return env->NewStringUTF(buffer);
}
}