Skip to content

Commit a92c4a5

Browse files
olszomalmtrojnar
authored andcommitted
Do not return corrupted CMS_ContentInfo
1 parent dc44ed5 commit a92c4a5

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

osslsigncode.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,6 +1734,7 @@ static time_t time_t_timestamp_get_attributes(CMS_ContentInfo **timestamp, PKCS7
17341734
if (!strcmp(object_txt, PKCS9_COUNTER_SIGNATURE)) {
17351735
/* Authenticode Timestamp - Policy OID: 1.2.840.113549.1.9.6 */
17361736
const u_char *data;
1737+
CMS_ContentInfo *cms;
17371738
PKCS7_SIGNER_INFO *countersi;
17381739
value = X509_ATTRIBUTE_get0_data(attr, 0, V_ASN1_SEQUENCE, NULL);
17391740
if (value == NULL)
@@ -1747,10 +1748,13 @@ static time_t time_t_timestamp_get_attributes(CMS_ContentInfo **timestamp, PKCS7
17471748
}
17481749
time = time_t_get_si_time(countersi);
17491750
if (time != INVALID_TIME) {
1750-
*timestamp = cms_get_timestamp(p7->d.sign, countersi);
1751-
if (*timestamp) {
1752-
if (!print_cms_timestamp(*timestamp, time))
1751+
cms = cms_get_timestamp(p7->d.sign, countersi);
1752+
if (cms) {
1753+
if (!print_cms_timestamp(cms, time)) {
1754+
CMS_ContentInfo_free(cms);
17531755
return INVALID_TIME; /* FAILED */
1756+
}
1757+
*timestamp = cms;
17541758
} else {
17551759
printf("Error: Corrupt Authenticode Timestamp embedded content\n");
17561760
}
@@ -1761,23 +1765,27 @@ static time_t time_t_timestamp_get_attributes(CMS_ContentInfo **timestamp, PKCS7
17611765
} else if (!strcmp(object_txt, SPC_RFC3161_OBJID)) {
17621766
/* RFC3161 Timestamp - Policy OID: 1.3.6.1.4.1.311.3.3.1 */
17631767
const u_char *data;
1768+
CMS_ContentInfo *cms;
17641769
value = X509_ATTRIBUTE_get0_data(attr, 0, V_ASN1_SEQUENCE, NULL);
17651770
if (value == NULL)
17661771
continue;
17671772
data = ASN1_STRING_get0_data(value);
1768-
*timestamp = d2i_CMS_ContentInfo(NULL, &data, ASN1_STRING_length(value));
1769-
if (*timestamp == NULL) {
1773+
cms = d2i_CMS_ContentInfo(NULL, &data, ASN1_STRING_length(value));
1774+
if (cms == NULL) {
17701775
printf("Error: RFC3161 Timestamp could not be decoded correctly\n");
17711776
ERR_print_errors_fp(stdout);
17721777
continue;
17731778
}
1774-
time = time_t_get_cms_time(*timestamp);
1779+
time = time_t_get_cms_time(cms);
17751780
if (time != INVALID_TIME) {
1776-
if (!print_cms_timestamp(*timestamp, time))
1781+
if (!print_cms_timestamp(cms, time)) {
1782+
CMS_ContentInfo_free(cms);
17771783
return INVALID_TIME; /* FAILED */
1784+
}
1785+
*timestamp = cms;
17781786
} else {
17791787
printf("Error: Corrupt RFC3161 Timestamp embedded content\n");
1780-
CMS_ContentInfo_free(*timestamp);
1788+
CMS_ContentInfo_free(cms);
17811789
ERR_print_errors_fp(stdout);
17821790
}
17831791
} else if (!strcmp(object_txt, SPC_UNAUTHENTICATED_DATA_BLOB_OBJID)) {

0 commit comments

Comments
 (0)