Skip to content

Commit

Permalink
[core] Fixed wrong null-safety condition check in haicrypt (#2616).
Browse files Browse the repository at this point in the history
  • Loading branch information
ethouris authored Jan 25, 2023
1 parent 30f6f6b commit a42a39f
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions haicrypt/hcrypt_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ int HaiCrypt_Tx_GetBuf(HaiCrypt_Handle hhc, size_t data_len, unsigned char **in_
return(crypto->msg_info->pfx_len);
}

int HaiCrypt_Tx_ManageKeys(HaiCrypt_Handle hhc, void *out_p[], size_t out_len_p[], int maxout)
int HaiCrypt_Tx_ManageKeys(HaiCrypt_Handle hhc, void *out_p[], size_t out_len_p[], int maxout)
{
hcrypt_Session *crypto = (hcrypt_Session *)hhc;
hcrypt_Ctx *ctx = crypto->ctx;
hcrypt_Ctx *ctx = NULL;
int nbout = 0;

if ((NULL == crypto)
|| (NULL == ctx)
|| (NULL == (ctx = crypto->ctx))
|| (NULL == out_p)
|| (NULL == out_len_p)) {
HCRYPT_LOG(LOG_ERR, "ManageKeys: invalid params: crypto=%p crypto->ctx=%p\n", crypto, ctx);
Expand All @@ -69,11 +69,6 @@ int HaiCrypt_Tx_ManageKeys(HaiCrypt_Handle hhc, void *out_p[], size_t out_len_p[
/* Manage Key Material (refresh, announce, decommission) */
hcryptCtx_Tx_ManageKM(crypto);

ctx = crypto->ctx;
if (NULL == ctx) {
HCRYPT_LOG(LOG_ERR, "%s", "crypto context not defined\n");
return(-1);
}
ASSERT(ctx->status == HCRYPT_CTX_S_ACTIVE);

nbout = hcryptCtx_Tx_InjectKM(crypto, out_p, out_len_p, maxout);
Expand All @@ -83,30 +78,30 @@ int HaiCrypt_Tx_ManageKeys(HaiCrypt_Handle hhc, void *out_p[], size_t out_len_p[
int HaiCrypt_Tx_GetKeyFlags(HaiCrypt_Handle hhc)
{
hcrypt_Session *crypto = (hcrypt_Session *)hhc;
hcrypt_Ctx *ctx = crypto->ctx;
hcrypt_Ctx *ctx = NULL;

if ((NULL == crypto)
|| (NULL == ctx)){
|| (NULL == (ctx = crypto->ctx))) {
HCRYPT_LOG(LOG_ERR, "GetKeyFlags: invalid params: crypto=%p crypto->ctx=%p\n", crypto, ctx);
return(-1);
}
return(hcryptCtx_GetKeyFlags(ctx));
return(hcryptCtx_GetKeyFlags(crypto->ctx));
}

int HaiCrypt_Tx_Data(HaiCrypt_Handle hhc,
unsigned char *in_pfx, unsigned char *in_data, size_t in_len)
int HaiCrypt_Tx_Data(HaiCrypt_Handle hhc,
unsigned char *in_pfx, unsigned char *in_data, size_t in_len)
{
hcrypt_Session *crypto = (hcrypt_Session *)hhc;
hcrypt_Ctx *ctx = crypto->ctx;
hcrypt_Ctx *ctx = NULL;
int nbout = 0;

if ((NULL == crypto)
|| (NULL == ctx)){
|| (NULL == (ctx = crypto->ctx))) {
HCRYPT_LOG(LOG_ERR, "Tx_Data: invalid params: crypto=%p crypto->ctx=%p\n", crypto, ctx);
return(-1);
}
/* Get/Set packet index */
ctx->msg_info->indexMsg(in_pfx, ctx->MSpfx_cache);
ctx->msg_info->indexMsg(in_pfx, ctx->MSpfx_cache);

if (hcryptMsg_GetKeyIndex(ctx->msg_info, in_pfx) != hcryptCtx_GetKeyIndex(ctx))
{
Expand All @@ -130,16 +125,16 @@ int HaiCrypt_Tx_Data(HaiCrypt_Handle hhc,
return(nbout);
}

int HaiCrypt_Tx_Process(HaiCrypt_Handle hhc,
unsigned char *in_msg, size_t in_len,
int HaiCrypt_Tx_Process(HaiCrypt_Handle hhc,
unsigned char *in_msg, size_t in_len,
void *out_p[], size_t out_len_p[], int maxout)
{
hcrypt_Session *crypto = (hcrypt_Session *)hhc;
hcrypt_Ctx *ctx = crypto->ctx;
hcrypt_Ctx *ctx = NULL;
int nb, nbout = 0;

if ((NULL == crypto)
|| (NULL == ctx)
|| (NULL == (ctx = crypto->ctx))
|| (NULL == out_p)
|| (NULL == out_len_p)) {
HCRYPT_LOG(LOG_ERR, "Tx_Process: invalid params: crypto=%p crypto->ctx=%p\n", crypto, ctx);
Expand All @@ -149,11 +144,6 @@ int HaiCrypt_Tx_Process(HaiCrypt_Handle hhc,
/* Manage Key Material (refresh, announce, decommission) */
hcryptCtx_Tx_ManageKM(crypto);

ctx = crypto->ctx;
if (NULL == ctx) {
HCRYPT_LOG(LOG_ERR, "%s", "crypto context not defined\n");
return(-1);
}
ASSERT(ctx->status == HCRYPT_CTX_S_ACTIVE);

nbout += hcryptCtx_Tx_InjectKM(crypto, out_p, out_len_p, maxout);
Expand Down

0 comments on commit a42a39f

Please sign in to comment.