projects
/
BearSSL
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
5281cd0
)
Small improvement to tolerate PEM files missing the terminating newline in the brssl...
author
Thomas Pornin
<pornin@bolet.org>
Sun, 19 Mar 2017 19:46:16 +0000
(20:46 +0100)
committer
Thomas Pornin
<pornin@bolet.org>
Sun, 19 Mar 2017 19:46:16 +0000
(20:46 +0100)
tools/files.c
patch
|
blob
|
history
diff --git
a/tools/files.c
b/tools/files.c
index
651d51a
..
8bf67cc
100644
(file)
--- a/
tools/files.c
+++ b/
tools/files.c
@@
-171,6
+171,7
@@
decode_pem(const void *src, size_t len, size_t *num)
const unsigned char *buf;
bvector bv = VEC_INIT;
int inobj;
const unsigned char *buf;
bvector bv = VEC_INIT;
int inobj;
+ int extra_nl;
*num = 0;
br_pem_decoder_init(&pc);
*num = 0;
br_pem_decoder_init(&pc);
@@
-179,6
+180,7
@@
decode_pem(const void *src, size_t len, size_t *num)
po.name = NULL;
po.data = NULL;
po.data_len = 0;
po.name = NULL;
po.data = NULL;
po.data_len = 0;
+ extra_nl = 1;
while (len > 0) {
size_t tlen;
while (len > 0) {
size_t tlen;
@@
-214,6
+216,19
@@
decode_pem(const void *src, size_t len, size_t *num)
VEC_CLEAREXT(pem_list, &free_pem_object_contents);
return NULL;
}
VEC_CLEAREXT(pem_list, &free_pem_object_contents);
return NULL;
}
+
+ /*
+ * We add an extra newline at the end, in order to
+ * support PEM files that lack the newline on their last
+ * line (this is somwehat invalid, but PEM format is not
+ * standardised and such files do exist in the wild, so
+ * we'd better accept them).
+ */
+ if (len == 0 && extra_nl) {
+ extra_nl = 0;
+ buf = (const unsigned char *)"\n";
+ len = 1;
+ }
}
if (inobj) {
fprintf(stderr, "ERROR: unfinished PEM object\n");
}
if (inobj) {
fprintf(stderr, "ERROR: unfinished PEM object\n");