Skip to content

Commit

Permalink
ESYS/FAPI: Fix order of calloc parameters.
Browse files Browse the repository at this point in the history
In some calloc calls the parameters number of elements and
size were swapped. Fixes #2820.

Signed-off-by: Juergen Repp <juergen_repp@web.de>
  • Loading branch information
JuergenReppSIT authored and AndreasFuchsTPM committed Apr 29, 2024
1 parent 46a1079 commit 8d19bd1
Show file tree
Hide file tree
Showing 59 changed files with 99 additions and 99 deletions.
2 changes: 1 addition & 1 deletion src/tss2-esys/api/Esys_AC_GetCapability.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ TSS2_RC Esys_AC_GetCapability_Finish(

/* Allocate memory for response parameters */
if (capabilityData != NULL) {
*capabilityData = calloc(sizeof(TPML_AC_CAPABILITIES), 1);
*capabilityData = calloc(1, sizeof(TPML_AC_CAPABILITIES));
if (*capabilityData == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
Expand Down
2 changes: 1 addition & 1 deletion src/tss2-esys/api/Esys_AC_Send.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ TSS2_RC Esys_AC_Send_Finish(

/* Allocate memory for response parameters */
if (acDataOut != NULL) {
*acDataOut = calloc(sizeof(TPMS_AC_OUTPUT), 1);
*acDataOut = calloc(1, sizeof(TPMS_AC_OUTPUT));
if (*acDataOut == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
Expand Down
2 changes: 1 addition & 1 deletion src/tss2-esys/api/Esys_ActivateCredential.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ Esys_ActivateCredential_Finish(

/* Allocate memory for response parameters */
if (certInfo != NULL) {
*certInfo = calloc(sizeof(TPM2B_DIGEST), 1);
*certInfo = calloc(1, sizeof(TPM2B_DIGEST));
if (*certInfo == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
Expand Down
4 changes: 2 additions & 2 deletions src/tss2-esys/api/Esys_Certify.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,13 @@ Esys_Certify_Finish(

/* Allocate memory for response parameters */
if (certifyInfo != NULL) {
*certifyInfo = calloc(sizeof(TPM2B_ATTEST), 1);
*certifyInfo = calloc(1, sizeof(TPM2B_ATTEST));
if (*certifyInfo == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
}
if (signature != NULL) {
*signature = calloc(sizeof(TPMT_SIGNATURE), 1);
*signature = calloc(1, sizeof(TPMT_SIGNATURE));
if (*signature == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
Expand Down
4 changes: 2 additions & 2 deletions src/tss2-esys/api/Esys_CertifyCreation.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,13 @@ Esys_CertifyCreation_Finish(

/* Allocate memory for response parameters */
if (certifyInfo != NULL) {
*certifyInfo = calloc(sizeof(TPM2B_ATTEST), 1);
*certifyInfo = calloc(1, sizeof(TPM2B_ATTEST));
if (*certifyInfo == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
}
if (signature != NULL) {
*signature = calloc(sizeof(TPMT_SIGNATURE), 1);
*signature = calloc(1, sizeof(TPMT_SIGNATURE));
if (*signature == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
Expand Down
6 changes: 3 additions & 3 deletions src/tss2-esys/api/Esys_CertifyX509.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,19 +293,19 @@ Esys_CertifyX509_Finish(

/* Allocate memory for response parameters */
if (addedToCertificate != NULL) {
*addedToCertificate = calloc(sizeof(TPM2B_MAX_BUFFER), 1);
*addedToCertificate = calloc(1, sizeof(TPM2B_MAX_BUFFER));
if (*addedToCertificate == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
}
if (tbsDigest != NULL) {
*tbsDigest = calloc(sizeof(TPM2B_DIGEST), 1);
*tbsDigest = calloc(1, sizeof(TPM2B_DIGEST));
if (*tbsDigest == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
}
if (signature != NULL) {
*signature = calloc(sizeof(TPMT_SIGNATURE), 1);
*signature = calloc(1, sizeof(TPMT_SIGNATURE));
if (*signature == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
Expand Down
6 changes: 3 additions & 3 deletions src/tss2-esys/api/Esys_Commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,19 +286,19 @@ Esys_Commit_Finish(

/* Allocate memory for response parameters */
if (K != NULL) {
*K = calloc(sizeof(TPM2B_ECC_POINT), 1);
*K = calloc(1, sizeof(TPM2B_ECC_POINT));
if (*K == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
}
if (L != NULL) {
*L = calloc(sizeof(TPM2B_ECC_POINT), 1);
*L = calloc(1, sizeof(TPM2B_ECC_POINT));
if (*L == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
}
if (E != NULL) {
*E = calloc(sizeof(TPM2B_ECC_POINT), 1);
*E = calloc(1, sizeof(TPM2B_ECC_POINT));
if (*E == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tss2-esys/api/Esys_ContextSave.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ Esys_ContextSave_Finish(
esysContext->state = _ESYS_STATE_INTERNALERROR;

/* Allocate memory for response parameters */
lcontext = calloc(sizeof(TPMS_CONTEXT), 1);
lcontext = calloc(1, sizeof(TPMS_CONTEXT));
if (lcontext == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
Expand Down
10 changes: 5 additions & 5 deletions src/tss2-esys/api/Esys_Create.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,31 +335,31 @@ Esys_Create_Finish(

/* Allocate memory for response parameters */
if (outPrivate != NULL) {
*outPrivate = calloc(sizeof(TPM2B_PRIVATE), 1);
*outPrivate = calloc(1, sizeof(TPM2B_PRIVATE));
if (*outPrivate == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
}
if (outPublic != NULL) {
*outPublic = calloc(sizeof(TPM2B_PUBLIC), 1);
*outPublic = calloc(1, sizeof(TPM2B_PUBLIC));
if (*outPublic == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
}
if (creationData != NULL) {
*creationData = calloc(sizeof(TPM2B_CREATION_DATA), 1);
*creationData = calloc(1, sizeof(TPM2B_CREATION_DATA));
if (*creationData == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
}
if (creationHash != NULL) {
*creationHash = calloc(sizeof(TPM2B_DIGEST), 1);
*creationHash = calloc(1, sizeof(TPM2B_DIGEST));
if (*creationHash == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
}
if (creationTicket != NULL) {
*creationTicket = calloc(sizeof(TPMT_TK_CREATION), 1);
*creationTicket = calloc(1, sizeof(TPMT_TK_CREATION));
if (*creationTicket == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
Expand Down
4 changes: 2 additions & 2 deletions src/tss2-esys/api/Esys_CreateLoaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,12 @@ Esys_CreateLoaded_Finish(
return r;

if (outPrivate != NULL) {
*outPrivate = calloc(sizeof(TPM2B_PRIVATE), 1);
*outPrivate = calloc(1, sizeof(TPM2B_PRIVATE));
if (*outPrivate == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
}
loutPublic = calloc(sizeof(TPM2B_PUBLIC), 1);
loutPublic = calloc(1, sizeof(TPM2B_PUBLIC));
if (loutPublic == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
Expand Down
8 changes: 4 additions & 4 deletions src/tss2-esys/api/Esys_CreatePrimary.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,24 +344,24 @@ Esys_CreatePrimary_Finish(
if (r != TSS2_RC_SUCCESS)
return r;

loutPublic = calloc(sizeof(TPM2B_PUBLIC), 1);
loutPublic = calloc(1, sizeof(TPM2B_PUBLIC));
if (loutPublic == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
if (creationData != NULL) {
*creationData = calloc(sizeof(TPM2B_CREATION_DATA), 1);
*creationData = calloc(1, sizeof(TPM2B_CREATION_DATA));
if (*creationData == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
}
if (creationHash != NULL) {
*creationHash = calloc(sizeof(TPM2B_DIGEST), 1);
*creationHash = calloc(1, sizeof(TPM2B_DIGEST));
if (*creationHash == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
}
if (creationTicket != NULL) {
*creationTicket = calloc(sizeof(TPMT_TK_CREATION), 1);
*creationTicket = calloc(1, sizeof(TPMT_TK_CREATION));
if (*creationTicket == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
Expand Down
6 changes: 3 additions & 3 deletions src/tss2-esys/api/Esys_Duplicate.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,19 @@ Esys_Duplicate_Finish(

/* Allocate memory for response parameters */
if (encryptionKeyOut != NULL) {
*encryptionKeyOut = calloc(sizeof(TPM2B_DATA), 1);
*encryptionKeyOut = calloc(1, sizeof(TPM2B_DATA));
if (*encryptionKeyOut == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
}
if (duplicate != NULL) {
*duplicate = calloc(sizeof(TPM2B_PRIVATE), 1);
*duplicate = calloc(1, sizeof(TPM2B_PRIVATE));
if (*duplicate == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
}
if (outSymSeed != NULL) {
*outSymSeed = calloc(sizeof(TPM2B_ENCRYPTED_SECRET), 1);
*outSymSeed = calloc(1, sizeof(TPM2B_ENCRYPTED_SECRET));
if (*outSymSeed == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tss2-esys/api/Esys_ECC_Parameters.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ Esys_ECC_Parameters_Finish(

/* Allocate memory for response parameters */
if (parameters != NULL) {
*parameters = calloc(sizeof(TPMS_ALGORITHM_DETAIL_ECC), 1);
*parameters = calloc(1, sizeof(TPMS_ALGORITHM_DETAIL_ECC));
if (*parameters == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
Expand Down
4 changes: 2 additions & 2 deletions src/tss2-esys/api/Esys_ECDH_KeyGen.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,13 @@ Esys_ECDH_KeyGen_Finish(

/* Allocate memory for response parameters */
if (zPoint != NULL) {
*zPoint = calloc(sizeof(TPM2B_ECC_POINT), 1);
*zPoint = calloc(1, sizeof(TPM2B_ECC_POINT));
if (*zPoint == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
}
if (pubPoint != NULL) {
*pubPoint = calloc(sizeof(TPM2B_ECC_POINT), 1);
*pubPoint = calloc(1, sizeof(TPM2B_ECC_POINT));
if (*pubPoint == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tss2-esys/api/Esys_ECDH_ZGen.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ Esys_ECDH_ZGen_Finish(

/* Allocate memory for response parameters */
if (outPoint != NULL) {
*outPoint = calloc(sizeof(TPM2B_ECC_POINT), 1);
*outPoint = calloc(1, sizeof(TPM2B_ECC_POINT));
if (*outPoint == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
Expand Down
2 changes: 1 addition & 1 deletion src/tss2-esys/api/Esys_EC_Ephemeral.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Esys_EC_Ephemeral_Finish(

/* Allocate memory for response parameters */
if (Q != NULL) {
*Q = calloc(sizeof(TPM2B_ECC_POINT), 1);
*Q = calloc(1, sizeof(TPM2B_ECC_POINT));
if (*Q == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
Expand Down
4 changes: 2 additions & 2 deletions src/tss2-esys/api/Esys_EncryptDecrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,13 @@ Esys_EncryptDecrypt_Finish(

/* Allocate memory for response parameters */
if (outData != NULL) {
*outData = calloc(sizeof(TPM2B_MAX_BUFFER), 1);
*outData = calloc(1, sizeof(TPM2B_MAX_BUFFER));
if (*outData == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
}
if (ivOut != NULL) {
*ivOut = calloc(sizeof(TPM2B_IV), 1);
*ivOut = calloc(1, sizeof(TPM2B_IV));
if (*ivOut == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
Expand Down
4 changes: 2 additions & 2 deletions src/tss2-esys/api/Esys_EncryptDecrypt2.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,13 @@ Esys_EncryptDecrypt2_Finish(

/* Allocate memory for response parameters */
if (outData != NULL) {
*outData = calloc(sizeof(TPM2B_MAX_BUFFER), 1);
*outData = calloc(1, sizeof(TPM2B_MAX_BUFFER));
if (*outData == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
}
if (ivOut != NULL) {
*ivOut = calloc(sizeof(TPM2B_IV), 1);
*ivOut = calloc(1, sizeof(TPM2B_IV));
if (*ivOut == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tss2-esys/api/Esys_EventSequenceComplete.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ Esys_EventSequenceComplete_Finish(

/* Allocate memory for response parameters */
if (results != NULL) {
*results = calloc(sizeof(TPML_DIGEST_VALUES), 1);
*results = calloc(1, sizeof(TPML_DIGEST_VALUES));
if (*results == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
Expand Down
4 changes: 2 additions & 2 deletions src/tss2-esys/api/Esys_FieldUpgradeData.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ Esys_FieldUpgradeData_Finish(

/* Allocate memory for response parameters */
if (nextDigest != NULL) {
*nextDigest = calloc(sizeof(TPMT_HA), 1);
*nextDigest = calloc(1, sizeof(TPMT_HA));
if (*nextDigest == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
}
if (firstDigest != NULL) {
*firstDigest = calloc(sizeof(TPMT_HA), 1);
*firstDigest = calloc(1, sizeof(TPMT_HA));
if (*firstDigest == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tss2-esys/api/Esys_FirmwareRead.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ Esys_FirmwareRead_Finish(

/* Allocate memory for response parameters */
if (fuData != NULL) {
*fuData = calloc(sizeof(TPM2B_MAX_BUFFER), 1);
*fuData = calloc(1, sizeof(TPM2B_MAX_BUFFER));
if (*fuData == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
Expand Down
2 changes: 1 addition & 1 deletion src/tss2-esys/api/Esys_GetCapability.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ Esys_GetCapability_Finish(

/* Allocate memory for response parameters */
if (capabilityData != NULL) {
*capabilityData = calloc(sizeof(TPMS_CAPABILITY_DATA), 1);
*capabilityData = calloc(1, sizeof(TPMS_CAPABILITY_DATA));
if (*capabilityData == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
Expand Down
4 changes: 2 additions & 2 deletions src/tss2-esys/api/Esys_GetCommandAuditDigest.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,13 @@ Esys_GetCommandAuditDigest_Finish(

/* Allocate memory for response parameters */
if (auditInfo != NULL) {
*auditInfo = calloc(sizeof(TPM2B_ATTEST), 1);
*auditInfo = calloc(1, sizeof(TPM2B_ATTEST));
if (*auditInfo == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
}
if (signature != NULL) {
*signature = calloc(sizeof(TPMT_SIGNATURE), 1);
*signature = calloc(1, sizeof(TPMT_SIGNATURE));
if (*signature == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tss2-esys/api/Esys_GetRandom.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ Esys_GetRandom_Finish(

/* Allocate memory for response parameters */
if (randomBytes != NULL) {
*randomBytes = calloc(sizeof(TPM2B_DIGEST), 1);
*randomBytes = calloc(1, sizeof(TPM2B_DIGEST));
if (*randomBytes == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
Expand Down
4 changes: 2 additions & 2 deletions src/tss2-esys/api/Esys_GetSessionAuditDigest.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,13 @@ Esys_GetSessionAuditDigest_Finish(

/* Allocate memory for response parameters */
if (auditInfo != NULL) {
*auditInfo = calloc(sizeof(TPM2B_ATTEST), 1);
*auditInfo = calloc(1, sizeof(TPM2B_ATTEST));
if (*auditInfo == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
}
if (signature != NULL) {
*signature = calloc(sizeof(TPMT_SIGNATURE), 1);
*signature = calloc(1, sizeof(TPMT_SIGNATURE));
if (*signature == NULL) {
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tss2-esys/api/Esys_GetTestResult.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ Esys_GetTestResult_Finish(

/* Allocate memory for response parameters */
if (outData != NULL) {
*outData = calloc(sizeof(TPM2B_MAX_BUFFER), 1);
*outData = calloc(1, sizeof(TPM2B_MAX_BUFFER));
if (*outData == NULL) {
return_error(TSS2_ESYS_RC_MEMORY, "Out of memory");
}
Expand Down
Loading

0 comments on commit 8d19bd1

Please sign in to comment.