]> granicus.if.org Git - p11-kit/commitdiff
trust: Fix use of invalid memory in PEM parser
authorStef Walter <stef@thewalter.net>
Fri, 8 Aug 2014 07:40:44 +0000 (09:40 +0200)
committerStef Walter <stef@thewalter.net>
Fri, 8 Aug 2014 07:59:20 +0000 (09:59 +0200)
trust/pem.c

index 7fe0076519ec44bc878c587cc1b1485c7d66989e..ce4f5547133c957843613b712a48f8ece32aec8d 100644 (file)
@@ -85,10 +85,8 @@ pem_find_begin (const char *data,
        if (type) {
                pref += ARMOR_PREF_BEGIN_L;
                assert (suff > pref);
-               *type = malloc (suff - pref + 1);
+               *type = strndup (pref, suff - pref);
                return_val_if_fail (*type != NULL, NULL);
-               memcpy (*type, pref, suff - pref);
-               (*type)[suff - pref] = 0;
        }
 
        /* The byte after this ---BEGIN--- */