sizeof style

This commit is contained in:
olszomal 2021-04-26 10:48:53 +02:00
parent 1bdfcc8940
commit 8b064ca814

View File

@ -1422,7 +1422,7 @@ static SpcLink *get_obsolete_link(void)
link->value.file = SpcString_new(); link->value.file = SpcString_new();
link->value.file->type = 0; link->value.file->type = 0;
link->value.file->value.unicode = ASN1_BMPSTRING_new(); link->value.file->value.unicode = ASN1_BMPSTRING_new();
ASN1_STRING_set(link->value.file->value.unicode, obsolete, sizeof(obsolete)); ASN1_STRING_set(link->value.file->value.unicode, obsolete, sizeof obsolete);
return link; return link;
} }
@ -1434,7 +1434,7 @@ static const unsigned char classid_page_hash[] = {
static unsigned char *pe_calc_page_hash(char *indata, uint32_t header_size, static unsigned char *pe_calc_page_hash(char *indata, uint32_t header_size,
int pe32plus, uint32_t sigpos, int phtype, size_t *rphlen) int pe32plus, uint32_t sigpos, int phtype, size_t *rphlen)
{ {
uint16_t nsections, sizeofopthdr; uint16_t nsections, opthdr_size;
uint32_t pagesize, hdrsize; uint32_t pagesize, hdrsize;
uint32_t rs, ro, l, lastpos = 0; uint32_t rs, ro, l, lastpos = 0;
int pphlen, phlen, i, pi = 1; int pphlen, phlen, i, pi = 1;
@ -1463,8 +1463,8 @@ static unsigned char *pe_calc_page_hash(char *indata, uint32_t header_size,
memset(res, 0, 4); memset(res, 0, 4);
EVP_DigestFinal(mdctx, res + 4, NULL); EVP_DigestFinal(mdctx, res + 4, NULL);
sizeofopthdr = GET_UINT16_LE(indata + header_size + 20); opthdr_size = GET_UINT16_LE(indata + header_size + 20);
sections = indata + header_size + 24 + sizeofopthdr; sections = indata + header_size + 24 + opthdr_size;
for (i=0; i<nsections; i++) { for (i=0; i<nsections; i++) {
rs = GET_UINT32_LE(sections + 16); rs = GET_UINT32_LE(sections + 16);
ro = GET_UINT32_LE(sections + 20); ro = GET_UINT32_LE(sections + 20);
@ -1554,7 +1554,7 @@ static SpcLink *get_page_hash_link(int phtype, char *indata, FILE_HEADER *header
sk_ASN1_TYPE_free(aset); sk_ASN1_TYPE_free(aset);
so = SpcSerializedObject_new(); so = SpcSerializedObject_new();
ASN1_OCTET_STRING_set(so->classId, classid_page_hash, sizeof(classid_page_hash)); ASN1_OCTET_STRING_set(so->classId, classid_page_hash, sizeof classid_page_hash);
ASN1_OCTET_STRING_set(so->serializedData, p, l); ASN1_OCTET_STRING_set(so->serializedData, p, l);
OPENSSL_free(p); OPENSSL_free(p);
@ -1614,7 +1614,7 @@ static void get_indirect_data_blob(u_char **blob, int *len, GLOBAL_OPTIONS *opti
ASN1_INTEGER_set(si->d, 0); ASN1_INTEGER_set(si->d, 0);
ASN1_INTEGER_set(si->e, 0); ASN1_INTEGER_set(si->e, 0);
ASN1_INTEGER_set(si->f, 0); ASN1_INTEGER_set(si->f, 0);
ASN1_OCTET_STRING_set(si->string, msistr, sizeof(msistr)); ASN1_OCTET_STRING_set(si->string, msistr, sizeof msistr);
l = i2d_SpcSipInfo(si, NULL); l = i2d_SpcSipInfo(si, NULL);
p = OPENSSL_malloc(l); p = OPENSSL_malloc(l);
i2d_SpcSipInfo(si, &p); i2d_SpcSipInfo(si, &p);
@ -1964,7 +1964,7 @@ static time_t si_get_time(PKCS7_SIGNER_INFO *si)
if (object == NULL) if (object == NULL)
return INVALID_TIME; /* FAILED */ return INVALID_TIME; /* FAILED */
object_txt[0] = 0x00; object_txt[0] = 0x00;
OBJ_obj2txt(object_txt, sizeof(object_txt), object, 1); OBJ_obj2txt(object_txt, sizeof object_txt, object, 1);
if (!strcmp(object_txt, PKCS9_SIGNING_TIME)) { if (!strcmp(object_txt, PKCS9_SIGNING_TIME)) {
/* PKCS#9 signing time - Policy OID: 1.2.840.113549.1.9.5 */ /* PKCS#9 signing time - Policy OID: 1.2.840.113549.1.9.5 */
time = X509_ATTRIBUTE_get0_data(attr, 0, V_ASN1_UTCTIME, NULL); time = X509_ATTRIBUTE_get0_data(attr, 0, V_ASN1_UTCTIME, NULL);
@ -2199,9 +2199,9 @@ static int print_attributes(SIGNATURE *signature, int verbose)
print_time_t(signature->signtime); print_time_t(signature->signtime);
if (signature->purpose) { if (signature->purpose) {
if (!memcmp(signature->purpose, purpose_comm, sizeof(purpose_comm))) if (!memcmp(signature->purpose, purpose_comm, sizeof purpose_comm))
printf("\tMicrosoft Commercial Code Signing purpose\n"); printf("\tMicrosoft Commercial Code Signing purpose\n");
else if (!memcmp(signature->purpose, purpose_ind, sizeof(purpose_ind))) else if (!memcmp(signature->purpose, purpose_ind, sizeof purpose_ind))
printf("\tMicrosoft Individual Code Signing purpose\n"); printf("\tMicrosoft Individual Code Signing purpose\n");
else else
printf("\tUnrecognized Code Signing purpose\n"); printf("\tUnrecognized Code Signing purpose\n");
@ -2213,7 +2213,7 @@ static int print_attributes(SIGNATURE *signature, int verbose)
printf("\tText description: %s\n", signature->desc); printf("\tText description: %s\n", signature->desc);
} }
if (signature->level) { if (signature->level) {
if (!memcmp(signature->level, java_attrs_low, sizeof(java_attrs_low))) if (!memcmp(signature->level, java_attrs_low, sizeof java_attrs_low))
printf("\tLow level of permissions in Microsoft Internet Explorer 4.x for CAB files\n"); printf("\tLow level of permissions in Microsoft Internet Explorer 4.x for CAB files\n");
else else
printf("\tUnrecognized level of permissions in Microsoft Internet Explorer 4.x for CAB files\n"); printf("\tUnrecognized level of permissions in Microsoft Internet Explorer 4.x for CAB files\n");
@ -2251,7 +2251,7 @@ static void get_signed_attributes(SIGNATURE *signature, STACK_OF(X509_ATTRIBUTE)
if (object == NULL) if (object == NULL)
continue; continue;
object_txt[0] = 0x00; object_txt[0] = 0x00;
OBJ_obj2txt(object_txt, sizeof(object_txt), object, 1); OBJ_obj2txt(object_txt, sizeof object_txt, object, 1);
if (!strcmp(object_txt, PKCS9_MESSAGE_DIGEST)) { if (!strcmp(object_txt, PKCS9_MESSAGE_DIGEST)) {
/* PKCS#9 message digest - Policy OID: 1.2.840.113549.1.9.4 */ /* PKCS#9 message digest - Policy OID: 1.2.840.113549.1.9.4 */
signature->digest = X509_ATTRIBUTE_get0_data(attr, 0, V_ASN1_OCTET_STRING, NULL); signature->digest = X509_ATTRIBUTE_get0_data(attr, 0, V_ASN1_OCTET_STRING, NULL);
@ -2317,7 +2317,7 @@ static void get_unsigned_attributes(STACK_OF(SIGNATURE) **signatures, SIGNATURE
if (object == NULL) if (object == NULL)
continue; continue;
object_txt[0] = 0x00; object_txt[0] = 0x00;
OBJ_obj2txt(object_txt, sizeof(object_txt), object, 1); OBJ_obj2txt(object_txt, sizeof object_txt, object, 1);
if (!strcmp(object_txt, PKCS9_COUNTER_SIGNATURE)) { if (!strcmp(object_txt, PKCS9_COUNTER_SIGNATURE)) {
/* Authenticode Timestamp - Policy OID: 1.2.840.113549.1.9.6 */ /* Authenticode Timestamp - Policy OID: 1.2.840.113549.1.9.6 */
PKCS7_SIGNER_INFO *countersi; PKCS7_SIGNER_INFO *countersi;
@ -3182,8 +3182,8 @@ static void pe_calc_digest(char *indata, const EVP_MD *md, unsigned char *mdbuf,
while (n < offset) { while (n < offset) {
int l; int l;
size_t want = offset - n; size_t want = offset - n;
if (want > sizeof(bfb)) if (want > sizeof bfb)
want = sizeof(bfb); want = sizeof bfb;
l = BIO_read(bio, bfb, want); l = BIO_read(bio, bfb, want);
if (l <= 0) if (l <= 0)
break; break;
@ -3224,8 +3224,8 @@ static void pe_extract_page_hash(SpcAttributeTypeAndOptionalValue *obj,
return; return;
} }
so = id->file->value.moniker; so = id->file->value.moniker;
if (so->classId->length != sizeof(classid_page_hash) || if (so->classId->length != sizeof classid_page_hash ||
memcmp(so->classId->data, classid_page_hash, sizeof (classid_page_hash))) { memcmp(so->classId->data, classid_page_hash, sizeof classid_page_hash)) {
SpcPeImageData_free(id); SpcPeImageData_free(id);
return; return;
} }
@ -3239,7 +3239,7 @@ static void pe_extract_page_hash(SpcAttributeTypeAndOptionalValue *obj,
*phtype = 0; *phtype = 0;
buf[0] = 0x00; buf[0] = 0x00;
OBJ_obj2txt(buf, sizeof(buf), obj->type, 1); OBJ_obj2txt(buf, sizeof buf, obj->type, 1);
if (!strcmp(buf, SPC_PE_IMAGE_PAGE_HASHES_V1)) { if (!strcmp(buf, SPC_PE_IMAGE_PAGE_HASHES_V1)) {
*phtype = NID_sha1; *phtype = NID_sha1;
} else if (!strcmp(buf, SPC_PE_IMAGE_PAGE_HASHES_V2)) { } else if (!strcmp(buf, SPC_PE_IMAGE_PAGE_HASHES_V2)) {
@ -3683,8 +3683,8 @@ static void cab_calc_digest(char *indata, const EVP_MD *md, unsigned char *mdbuf
while (coffFiles < offset) { while (coffFiles < offset) {
int l; int l;
uint32_t want = offset - coffFiles; uint32_t want = offset - coffFiles;
if (want > sizeof(bfb)) if (want > sizeof bfb)
want = sizeof(bfb); want = sizeof bfb;
l = BIO_read(bio, bfb, want); l = BIO_read(bio, bfb, want);
if (l <= 0) if (l <= 0)
break; break;
@ -4280,7 +4280,7 @@ static void add_jp_attribute(PKCS7_SIGNER_INFO *si, int jp)
switch (jp) { switch (jp) {
case 0: case 0:
attrs = java_attrs_low; attrs = java_attrs_low;
len = sizeof(java_attrs_low); len = sizeof java_attrs_low;
break; break;
case 1: case 1:
/* XXX */ /* XXX */
@ -4303,9 +4303,9 @@ static void add_purpose_attribute(PKCS7_SIGNER_INFO *si, int comm)
astr = ASN1_STRING_new(); astr = ASN1_STRING_new();
if (comm) { if (comm) {
ASN1_STRING_set(astr, purpose_comm, sizeof(purpose_comm)); ASN1_STRING_set(astr, purpose_comm, sizeof purpose_comm);
} else { } else {
ASN1_STRING_set(astr, purpose_ind, sizeof(purpose_ind)); ASN1_STRING_set(astr, purpose_ind, sizeof purpose_ind);
} }
PKCS7_add_signed_attribute(si, OBJ_txt2nid(SPC_STATEMENT_TYPE_OBJID), PKCS7_add_signed_attribute(si, OBJ_txt2nid(SPC_STATEMENT_TYPE_OBJID),
V_ASN1_SEQUENCE, astr); V_ASN1_SEQUENCE, astr);
@ -4428,8 +4428,8 @@ static int add_unauthenticated_blob(PKCS7 *sig)
if ((p = OPENSSL_malloc(len)) == NULL) if ((p = OPENSSL_malloc(len)) == NULL)
return 1; /* FAILED */ return 1; /* FAILED */
memset(p, 0, len); memset(p, 0, len);
memcpy(p, prefix, sizeof(prefix)); memcpy(p, prefix, sizeof prefix);
memcpy(p+len-sizeof(postfix), postfix, sizeof(postfix)); memcpy(p + len - sizeof postfix, postfix, sizeof postfix);
astr = ASN1_STRING_new(); astr = ASN1_STRING_new();
ASN1_STRING_set(astr, p, len); ASN1_STRING_set(astr, p, len);
nid = OBJ_create(SPC_UNAUTHENTICATED_DATA_BLOB_OBJID, nid = OBJ_create(SPC_UNAUTHENTICATED_DATA_BLOB_OBJID,
@ -4724,10 +4724,10 @@ static int get_file_type(char *indata, char *infile, file_type_t *type)
*type = FILE_TYPE_CAB; *type = FILE_TYPE_CAB;
} else if (!memcmp(indata, "MZ", 2)) { } else if (!memcmp(indata, "MZ", 2)) {
*type = FILE_TYPE_PE; *type = FILE_TYPE_PE;
} else if (!memcmp(indata, msi_magic, sizeof(msi_magic))) { } else if (!memcmp(indata, msi_magic, sizeof msi_magic)) {
*type = FILE_TYPE_MSI; *type = FILE_TYPE_MSI;
} else if (!memcmp(indata + ((GET_UINT8_LE(indata+1) == 0x82) ? 4 : 5), } else if (!memcmp(indata + ((GET_UINT8_LE(indata+1) == 0x82) ? 4 : 5),
pkcs7_signed_data, sizeof(pkcs7_signed_data))) { pkcs7_signed_data, sizeof pkcs7_signed_data)) {
/* the maximum size of a supported cat file is (2^24 -1) bytes */ /* the maximum size of a supported cat file is (2^24 -1) bytes */
*type = FILE_TYPE_CAT; *type = FILE_TYPE_CAT;
} else { } else {
@ -4755,7 +4755,7 @@ static char *getpassword(const char *prompt)
printf("Failed to set terminal attributes\n"); printf("Failed to set terminal attributes\n");
return NULL; return NULL;
} }
p = fgets(passbuf, sizeof(passbuf), stdin); p = fgets(passbuf, sizeof passbuf, stdin);
if (tcsetattr(fileno(stdin), TCSANOW, &ofl) != 0) if (tcsetattr(fileno(stdin), TCSANOW, &ofl) != 0)
printf("Failed to restore terminal attributes\n"); printf("Failed to restore terminal attributes\n");
if (!p) { if (!p) {
@ -4764,7 +4764,7 @@ static char *getpassword(const char *prompt)
} }
passbuf[strlen(passbuf)-1] = 0x00; passbuf[strlen(passbuf)-1] = 0x00;
pass = OPENSSL_strdup(passbuf); pass = OPENSSL_strdup(passbuf);
memset(passbuf, 0, sizeof(passbuf)); memset(passbuf, 0, sizeof passbuf);
return pass; return pass;
#else #else
return getpass(prompt); return getpass(prompt);
@ -4783,7 +4783,7 @@ static int read_password(GLOBAL_OPTIONS *options)
printf("Failed to open password file: %s\n", options->readpass); printf("Failed to open password file: %s\n", options->readpass);
return 0; /* FAILED */ return 0; /* FAILED */
} }
passlen = read(passfd, passbuf, sizeof(passbuf)-1); passlen = read(passfd, passbuf, sizeof passbuf - 1);
close(passfd); close(passfd);
if (passlen <= 0) { if (passlen <= 0) {
printf("Failed to read password from file: %s\n", options->readpass); printf("Failed to read password from file: %s\n", options->readpass);
@ -4791,7 +4791,7 @@ static int read_password(GLOBAL_OPTIONS *options)
} }
passbuf[passlen] = 0x00; passbuf[passlen] = 0x00;
options->pass = OPENSSL_strdup(passbuf); options->pass = OPENSSL_strdup(passbuf);
memset(passbuf, 0, sizeof(passbuf)); memset(passbuf, 0, sizeof passbuf);
#ifdef PROVIDE_ASKPASS #ifdef PROVIDE_ASKPASS
} else if (options->askpass) { } else if (options->askpass) {
options->pass = getpassword("Password: "); options->pass = getpassword("Password: ");
@ -5227,7 +5227,7 @@ static PKCS7 *get_sigfile(char *sigfile, file_type_t type)
printf("Failed to open file: %s\n", sigfile); printf("Failed to open file: %s\n", sigfile);
return NULL; /* FAILED */ return NULL; /* FAILED */
} }
if (sigfilesize >= sizeof(pemhdr) && !memcmp(insigdata, pemhdr, sizeof(pemhdr)-1)) { if (sigfilesize >= sizeof pemhdr && !memcmp(insigdata, pemhdr, sizeof pemhdr - 1)) {
sigbio = BIO_new_mem_buf(insigdata, sigfilesize); sigbio = BIO_new_mem_buf(insigdata, sigfilesize);
sig = PEM_read_bio_PKCS7(sigbio, NULL, NULL, NULL); sig = PEM_read_bio_PKCS7(sigbio, NULL, NULL, NULL);
BIO_free_all(sigbio); BIO_free_all(sigbio);