Skip to content

Commit

Permalink
pem: Fix assert condition
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ueno committed Jan 11, 2019
1 parent bebf4f3 commit f277a14
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion trust/pem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 18 additions & 0 deletions trust/test-pem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit f277a14

Please sign in to comment.