From: Art Cancro Date: Fri, 22 Jan 2016 19:40:10 +0000 (-0500) Subject: Removed libb64's behavior of automatically appending a newline to everything X-Git-Tag: Release_902~72 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=2eaed50b412bbec335b15321e058ed42b474dea3 Removed libb64's behavior of automatically appending a newline to everything it encodes. This is what broke listsub and probably other things as well. I deliberately changed the calling syntax of base64_encode_blockend() to make it break if someone tries to upgrade it later, so it will call their attention to this difference. --- diff --git a/libcitadel/lib/b64/cencode.c b/libcitadel/lib/b64/cencode.c index 64720f6cf..150125af9 100644 --- a/libcitadel/lib/b64/cencode.c +++ b/libcitadel/lib/b64/cencode.c @@ -1,9 +1,14 @@ -/* -cencoder.c - c source to a base64 encoding algorithm implementation - -This is part of the libb64 project, and has been placed in the public domain. -For details, see http://sourceforge.net/projects/libb64 -*/ +// +// cencoder.c - c source to a base64 encoding algorithm implementation +// +// This is part of the libb64 project, and has been placed in the public domain. +// For details, see http://sourceforge.net/projects/libb64 +// +// ** NOTE: MODIFIED BY AJC 2016JAN22 ** +// The libb64 distribution always places a newline at the end of an encoded block. +// We have removed that behavior. If libb64 is updated, make that change again. +// +// #include "b64/cencode.h" @@ -74,7 +79,7 @@ int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, return codechar - code_out; } -int base64_encode_blockend(char* code_out, base64_encodestate* state_in) +int base64_encode_blockend(char* code_out, base64_encodestate* state_in, int with_newline) { char* codechar = code_out; @@ -92,8 +97,10 @@ int base64_encode_blockend(char* code_out, base64_encodestate* state_in) case step_A: break; } - *codechar++ = '\r'; - *codechar++ = '\n'; + if (with_newline) { // added by ajc on 2016jan22, normally citadel doesn't want this + *codechar++ = '\r'; + *codechar++ = '\n'; + } return codechar - code_out; } diff --git a/libcitadel/lib/b64/cencode.h b/libcitadel/lib/b64/cencode.h index c1e3464af..81ea3b9bc 100644 --- a/libcitadel/lib/b64/cencode.h +++ b/libcitadel/lib/b64/cencode.h @@ -26,6 +26,6 @@ char base64_encode_value(char value_in); int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in); -int base64_encode_blockend(char* code_out, base64_encodestate* state_in); +int base64_encode_blockend(char* code_out, base64_encodestate* state_in, int with_newline); #endif /* BASE64_CENCODE_H */ diff --git a/libcitadel/lib/tools.c b/libcitadel/lib/tools.c index 14e43071a..ad541ddf1 100644 --- a/libcitadel/lib/tools.c +++ b/libcitadel/lib/tools.c @@ -317,12 +317,12 @@ size_t CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen, int li dest[destoffset++] = '\n'; } - destoffset += base64_encode_blockend(&(dest[destoffset]), &_state); + destoffset += base64_encode_blockend(&(dest[destoffset]), &_state, 0); } else { destoffset = base64_encode_block(source, sourcelen, dest, &_state); - destoffset += base64_encode_blockend(&(dest[destoffset]), &_state); + destoffset += base64_encode_blockend(&(dest[destoffset]), &_state, 0); } dest[destoffset] = 0; return destoffset;