1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-06 01:30:40 +03:00

Merge pull request #1833 from chipitsine/coverity_fix

several potential null pointer dereferences fix
This commit is contained in:
Ilya Shipitsin 2023-05-01 09:14:17 +02:00 committed by GitHub
commit 6ae786d542
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -404,6 +404,28 @@ bool WriteSecKey(SECURE *sec, bool private_obj, char *name, K *k)
UCHAR modules[MAX_SIZE], pub[MAX_SIZE], pri[MAX_SIZE], prime1[MAX_SIZE], prime2[MAX_SIZE]; UCHAR modules[MAX_SIZE], pub[MAX_SIZE], pri[MAX_SIZE], prime1[MAX_SIZE], prime2[MAX_SIZE];
UCHAR exp1[MAX_SIZE], exp2[MAX_SIZE], coeff[MAX_SIZE]; UCHAR exp1[MAX_SIZE], exp2[MAX_SIZE], coeff[MAX_SIZE];
const BIGNUM *n, *e, *d, *p, *q, *dmp1, *dmq1, *iqmp; const BIGNUM *n, *e, *d, *p, *q, *dmp1, *dmq1, *iqmp;
// Validate arguments
if (sec == NULL)
{
return false;
}
if (name == NULL || k == NULL || k->private_key == false)
{
sec->Error = SEC_ERROR_BAD_PARAMETER;
return false;
}
if (sec->SessionCreated == false)
{
sec->Error = SEC_ERROR_NO_SESSION;
return false;
}
if (sec->LoginFlag == false && private_obj)
{
sec->Error = SEC_ERROR_NOT_LOGIN;
return false;
}
CK_ATTRIBUTE a[] = CK_ATTRIBUTE a[] =
{ {
{CKA_MODULUS, modules, 0}, // 0 {CKA_MODULUS, modules, 0}, // 0
@ -430,27 +452,6 @@ bool WriteSecKey(SECURE *sec, bool private_obj, char *name, K *k)
{CKA_MODIFIABLE, &b_false, sizeof(b_false)}, {CKA_MODIFIABLE, &b_false, sizeof(b_false)},
}; };
// Validate arguments
if (sec == NULL)
{
return false;
}
if (name == NULL || k == NULL || k->private_key == false)
{
sec->Error = SEC_ERROR_BAD_PARAMETER;
return false;
}
if (sec->SessionCreated == false)
{
sec->Error = SEC_ERROR_NO_SESSION;
return false;
}
if (sec->LoginFlag == false && private_obj)
{
sec->Error = SEC_ERROR_NOT_LOGIN;
return false;
}
// Numeric data generation // Numeric data generation
rsa = EVP_PKEY_get0_RSA(k->pkey); rsa = EVP_PKEY_get0_RSA(k->pkey);
if (rsa == NULL) if (rsa == NULL)
@ -640,22 +641,6 @@ bool WriteSecCert(SECURE *sec, bool private_obj, char *name, X *x)
UINT ret; UINT ret;
BUF *b; BUF *b;
UINT object; UINT object;
CK_ATTRIBUTE a[] =
{
{CKA_SUBJECT, subject, 0}, // 0
{CKA_ISSUER, issuer, 0}, // 1
{CKA_SERIAL_NUMBER, serial_number, 0}, // 2
{CKA_VALUE, value, 0}, // 3
{CKA_CLASS, &obj_class, sizeof(obj_class)},
{CKA_TOKEN, &b_true, sizeof(b_true)},
{CKA_PRIVATE, &b_private_obj, sizeof(b_private_obj)},
{CKA_LABEL, name, StrLen(name)},
{CKA_CERTIFICATE_TYPE, &cert_type, sizeof(cert_type)},
#if 0 // Don't use these because some tokens fail
{CKA_START_DATE, &start_date, sizeof(start_date)},
{CKA_END_DATE, &end_date, sizeof(end_date)},
#endif
};
// Validate arguments // Validate arguments
if (sec == NULL) if (sec == NULL)
{ {
@ -677,6 +662,23 @@ bool WriteSecCert(SECURE *sec, bool private_obj, char *name, X *x)
return false; return false;
} }
CK_ATTRIBUTE a[] =
{
{CKA_SUBJECT, subject, 0}, // 0
{CKA_ISSUER, issuer, 0}, // 1
{CKA_SERIAL_NUMBER, serial_number, 0}, // 2
{CKA_VALUE, value, 0}, // 3
{CKA_CLASS, &obj_class, sizeof(obj_class)},
{CKA_TOKEN, &b_true, sizeof(b_true)},
{CKA_PRIVATE, &b_private_obj, sizeof(b_private_obj)},
{CKA_LABEL, name, StrLen(name)},
{CKA_CERTIFICATE_TYPE, &cert_type, sizeof(cert_type)},
#if 0 // Don't use these because some tokens fail
{CKA_START_DATE, &start_date, sizeof(start_date)},
{CKA_END_DATE, &end_date, sizeof(end_date)},
#endif
};
// Copy the certificate to the buffer // Copy the certificate to the buffer
b = XToBuf(x, false); b = XToBuf(x, false);
if (b == NULL) if (b == NULL)
@ -1313,14 +1315,6 @@ bool WriteSecData(SECURE *sec, bool private_obj, char *name, void *data, UINT si
UINT object_class = CKO_DATA; UINT object_class = CKO_DATA;
CK_BBOOL b_true = true, b_false = false, b_private_obj = private_obj; CK_BBOOL b_true = true, b_false = false, b_private_obj = private_obj;
UINT object; UINT object;
CK_ATTRIBUTE a[] =
{
{CKA_TOKEN, &b_true, sizeof(b_true)},
{CKA_CLASS, &object_class, sizeof(object_class)},
{CKA_PRIVATE, &b_private_obj, sizeof(b_private_obj)},
{CKA_LABEL, name, StrLen(name)},
{CKA_VALUE, data, size},
};
// Validate arguments // Validate arguments
if (sec == NULL) if (sec == NULL)
{ {
@ -1347,6 +1341,15 @@ bool WriteSecData(SECURE *sec, bool private_obj, char *name, void *data, UINT si
return false; return false;
} }
CK_ATTRIBUTE a[] =
{
{CKA_TOKEN, &b_true, sizeof(b_true)},
{CKA_CLASS, &object_class, sizeof(object_class)},
{CKA_PRIVATE, &b_private_obj, sizeof(b_private_obj)},
{CKA_LABEL, name, StrLen(name)},
{CKA_VALUE, data, size},
};
// Delete any objects with the same name // Delete any objects with the same name
if (CheckSecObject(sec, name, SEC_DATA)) if (CheckSecObject(sec, name, SEC_DATA))
{ {