]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Attempt to fix a leak in OpenPGP cert parsing.
authorAlex Gaynor <alex.gaynor@gmail.com>
Sat, 31 Dec 2016 02:17:22 +0000 (21:17 -0500)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 31 Dec 2016 17:11:20 +0000 (18:11 +0100)
lib/opencdk/read-packet.c
tests/cert-tests/data/attribute-leak-1.pub [new file with mode: 0644]
tests/cert-tests/openpgp-cert-parser

index a7575bf85f1cb63390d9dc93f5e4623a01a89cc8..faee419bc21a1fdd2c7a5d5ec90fd2533a3bfe87 100644 (file)
@@ -509,8 +509,10 @@ read_attribute(cdk_stream_t inp, size_t pktlen, cdk_pkt_userid_t attr,
        p++;
        len--;
 
-       if (len >= pktlen)
+       if (len >= pktlen) {
+               cdk_free(buf);
                return CDK_Inv_Packet;
+       }
        attr->attrib_img = cdk_calloc(1, len);
        if (!attr->attrib_img) {
                cdk_free(buf);
diff --git a/tests/cert-tests/data/attribute-leak-1.pub b/tests/cert-tests/data/attribute-leak-1.pub
new file mode 100644 (file)
index 0000000..6ab4334
Binary files /dev/null and b/tests/cert-tests/data/attribute-leak-1.pub differ
index 9545fa0c6c5dc1bf076965758c6fc8c9dabee2e2..c12e1be8d64fa7f1f3892b3a4fdcb8e6ebeb333a 100755 (executable)
@@ -38,4 +38,8 @@ echo "Checking OpenPGP certificate parsing"
        | grep "^import error: Error in parsing" > /dev/null) || \
        fail "Parsing should have errored"
 
+("${CERTTOOL}" --inraw --pgp-certificate-info --infile "${srcdir}/data/attribute-leak-1.pub" 2>&1 \
+       | grep "^import error:" > /dev/null) || \
+       fail "Parsing should have errored"
+
 exit ${RETCODE:-0}