]> granicus.if.org Git - p11-kit/commitdiff
pem: Fix assert condition
authorDaiki Ueno <dueno@redhat.com>
Fri, 11 Jan 2019 09:35:16 +0000 (10:35 +0100)
committerDaiki Ueno <ueno@gnu.org>
Fri, 11 Jan 2019 10:28:19 +0000 (11:28 +0100)
If the PEM header is "-----BEGIN -----", *type should be an empty
string and the parser shouldn't fail.  Reported by Han Han in:
https://bugzilla.redhat.com/show_bug.cgi?id=1665172

trust/pem.c
trust/test-pem.c

index ce4f5547133c957843613b712a48f8ece32aec8d..fae7dd649ee610b79ed254d8890cf9aac52954a9 100644 (file)
@@ -84,7 +84,7 @@ pem_find_begin (const char *data,
 
        if (type) {
                pref += ARMOR_PREF_BEGIN_L;
-               assert (suff > pref);
+               assert (suff >= pref);
                *type = strndup (pref, suff - pref);
                return_val_if_fail (*type != NULL, NULL);
        }
index 0c7d60a2758d05517d5f01477b38421674f3efb9..6feff86bc5ce6827b47c173d71a2df786903cc02 100644 (file)
@@ -119,6 +119,24 @@ struct {
          }
        },
 
+       {
+         /* one block with empty type */
+         "-----BEGIN -----\n"
+         "aYNNXqshlVxCdo8QfKeXh3GUzd/yn4LYIVgQrx4a\n"
+         "-----END -----",
+         {
+           {
+             "",
+             "\x69\x83\x4d\x5e\xab\x21\x95\x5c\x42\x76\x8f\x10\x7c\xa7\x97\x87"
+             "\x71\x94\xcd\xdf\xf2\x9f\x82\xd8\x21\x58\x10\xaf\x1e\x1a",
+             30,
+           },
+           {
+             NULL,
+           }
+         }
+       },
+
        {
          NULL,
        }