ID: 50 - ipmi_hpmfwupg needs a clean up

HpmfwupgValidateImageIntegrity() - re-write a bit to make it more compact.
This commit is contained in:
Zdenek Styblik 2013-10-10 12:17:22 +00:00
parent a8119d13a8
commit 7a0b451fd7

View File

@ -678,7 +678,6 @@ HpmfwupgUpgrade(struct ipmi_intf *intf, char *imageFilename, int activate,
int int
HpmfwupgValidateImageIntegrity(struct HpmfwupgUpgradeCtx *pFwupgCtx) HpmfwupgValidateImageIntegrity(struct HpmfwupgUpgradeCtx *pFwupgCtx)
{ {
int rc = HPMFWUPG_SUCCESS;
struct HpmfwupgImageHeader *pImageHeader = (struct HpmfwupgImageHeader*)pFwupgCtx->pImageData; struct HpmfwupgImageHeader *pImageHeader = (struct HpmfwupgImageHeader*)pFwupgCtx->pImageData;
md5_state_t ctx; md5_state_t ctx;
static unsigned char md[HPMFWUPG_MD5_SIGNATURE_LENGTH]; static unsigned char md[HPMFWUPG_MD5_SIGNATURE_LENGTH];
@ -693,33 +692,29 @@ HpmfwupgValidateImageIntegrity(struct HpmfwupgUpgradeCtx *pFwupgCtx)
md5_finish(&ctx, md); md5_finish(&ctx, md);
if (memcmp(md, pMd5Sig, HPMFWUPG_MD5_SIGNATURE_LENGTH) != 0) { if (memcmp(md, pMd5Sig, HPMFWUPG_MD5_SIGNATURE_LENGTH) != 0) {
lprintf(LOG_NOTICE, "\n Invalid MD5 signature"); lprintf(LOG_NOTICE, "\n Invalid MD5 signature");
rc = HPMFWUPG_ERROR; return HPMFWUPG_ERROR;
} }
if (rc == HPMFWUPG_SUCCESS) {
/* Validate Header signature */ /* Validate Header signature */
if(strncmp(pImageHeader->signature, if(strncmp(pImageHeader->signature,
HPMFWUPG_IMAGE_SIGNATURE, HPMFWUPG_IMAGE_SIGNATURE,
HPMFWUPG_HEADER_SIGNATURE_LENGTH) == 0) { HPMFWUPG_HEADER_SIGNATURE_LENGTH) != 0) {
lprintf(LOG_NOTICE,"\n Invalid image signature");
return HPMFWUPG_ERROR;
}
/* Validate Header image format version */ /* Validate Header image format version */
if (pImageHeader->formatVersion == HPMFWUPG_IMAGE_HEADER_VERSION) { if (pImageHeader->formatVersion != HPMFWUPG_IMAGE_HEADER_VERSION) {
lprintf(LOG_NOTICE,"\n Unrecognized image version");
return HPMFWUPG_ERROR;
}
/* Validate header checksum */ /* Validate header checksum */
if (HpmfwupgCalculateChecksum((unsigned char*)pImageHeader, if (HpmfwupgCalculateChecksum((unsigned char*)pImageHeader,
sizeof(struct HpmfwupgImageHeader) sizeof(struct HpmfwupgImageHeader)
+ pImageHeader->oemDataLength + pImageHeader->oemDataLength
+ sizeof(unsigned char)/*checksum*/) != 0) { + sizeof(unsigned char)/*checksum*/) != 0) {
lprintf(LOG_NOTICE,"\n Invalid header checksum"); lprintf(LOG_NOTICE,"\n Invalid header checksum");
rc = HPMFWUPG_ERROR; return HPMFWUPG_ERROR;
} }
} else { return HPMFWUPG_SUCCESS;
lprintf(LOG_NOTICE,"\n Unrecognized image version");
rc = HPMFWUPG_ERROR;
}
} else {
lprintf(LOG_NOTICE,"\n Invalid image signature");
rc = HPMFWUPG_ERROR;
}
}
return rc;
} }
/* HpmfwupgPreparationStage - prepere stage of a firmware upgrade procedure as /* HpmfwupgPreparationStage - prepere stage of a firmware upgrade procedure as