From 14fe544544b5cbb2a385f40780e9ffdb88c56ffe Mon Sep 17 00:00:00 2001 From: xiazhvera Date: Thu, 12 Oct 2023 18:31:09 -0700 Subject: [PATCH] handle windows endline --- source/pem.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/source/pem.c b/source/pem.c index 121d7f7e1..315a80826 100644 --- a/source/pem.c +++ b/source/pem.c @@ -232,11 +232,17 @@ int s_extract_header_type_cur(struct aws_byte_cursor cur, struct aws_byte_cursor } aws_byte_cursor_advance(&cur, s_begin_header_cur.len); - AWS_LOGF_ERROR(AWS_LS_IO_PEM, "Invalid PEM buffer: invalid end token %d:"PRInSTR, cur.len, AWS_BYTE_CURSOR_PRI(cur)); aws_byte_cursor_advance(&cur, 1); // space after begin - AWS_LOGF_ERROR(AWS_LS_IO_PEM, "Invalid PEM buffer: invalid end token %d:"PRInSTR, cur.len, AWS_BYTE_CURSOR_PRI(cur)); + + + /* handle CRLF on Windows by burning '\r' off the end of the buffer */ + if (cur.len && (cur.ptr[cur.len- 1] == '\r')) { + cur.len--; + } + struct aws_byte_cursor type_cur = aws_byte_cursor_advance(&cur, cur.len - s_delim_cur.len); + if (!aws_byte_cursor_eq(&cur, &s_delim_cur)) { AWS_LOGF_ERROR(AWS_LS_IO_PEM, "Invalid PEM buffer: invalid end token %d:"PRInSTR, cur.len, AWS_BYTE_CURSOR_PRI(cur)); return aws_raise_error(AWS_ERROR_PEM_MALFORMED);