diff options
author | Nick Mathewson <nickm@torproject.org> | 2020-03-11 09:40:04 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2020-03-11 10:35:17 -0400 |
commit | 5721ec22d8be99a6f24fa69d51d0cbdc4ff21739 (patch) | |
tree | 90902ecae014677c19b1fa20428c95a421b64371 /src/lib/encoding/pem.c | |
parent | b9c7c61ea5233854ff83257a8bc530b7e0a50351 (diff) | |
download | tor-5721ec22d8be99a6f24fa69d51d0cbdc4ff21739.tar.gz tor-5721ec22d8be99a6f24fa69d51d0cbdc4ff21739.zip |
pem_decode(): Tolerate CRLF line endings
Fixes bug 33032; bugfix on 0.3.5.1-alpha when we introduced our own
PEM decoder.
Diffstat (limited to 'src/lib/encoding/pem.c')
-rw-r--r-- | src/lib/encoding/pem.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/lib/encoding/pem.c b/src/lib/encoding/pem.c index 24b238b130..51f37d0840 100644 --- a/src/lib/encoding/pem.c +++ b/src/lib/encoding/pem.c @@ -85,13 +85,19 @@ pem_decode(uint8_t *dest, size_t destlen, const char *src, size_t srclen, src = eat_whitespace_eos(src, eos); char *tag = NULL; - tor_asprintf(&tag, "-----BEGIN %s-----\n", objtype); + tor_asprintf(&tag, "-----BEGIN %s-----", objtype); if ((size_t)(eos-src) < strlen(tag) || fast_memneq(src, tag, strlen(tag))) { tor_free(tag); return -1; } src += strlen(tag); tor_free(tag); + /* At this point we insist on spaces (including CR), then an LF. */ + src = eat_whitespace_eos_no_nl(src, eos); + if (src == eos || *src != '\n') { + /* Extra junk at end of line: this isn't valid. */ + return -1; + } // NOTE lack of trailing \n. We do not enforce its presence. tor_asprintf(&tag, "\n-----END %s-----", objtype); |