Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C] fix decode function #5642

Merged
merged 3 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ char *strReplace(char *orig, char *rep, char *with) {
return result;
}

char *sbi_base64encode (const void *b64_encode_this, int encode_this_many_bytes){
char *base64encode (const void *b64_encode_this, int encode_this_many_bytes){
#ifdef OPENSSL
BIO *b64_bio, *mem_bio; //Declares two OpenSSL BIOs: a base64 filter and a memory BIO.
BUF_MEM *mem_bio_mem_ptr; //Pointer to a "memory BIO" structure holding our base64 data.
Expand All @@ -597,7 +597,7 @@ char *sbi_base64encode (const void *b64_encode_this, int encode_this_many_bytes)
#endif
}

char *sbi_base64decode (const void *b64_decode_this, int decode_this_many_bytes){
char *base64decode (const void *b64_decode_this, int decode_this_many_bytes, int *decoded_bytes){
#ifdef OPENSSL
BIO *b64_bio, *mem_bio; //Declares two OpenSSL BIOs: a base64 filter and a memory BIO.
char *base64_decoded = calloc( (decode_this_many_bytes*3)/4+1, sizeof(char) ); //+1 = null.
Expand All @@ -611,6 +611,7 @@ char *sbi_base64decode (const void *b64_decode_this, int decode_this_many_bytes)
decoded_byte_index++; //Increment the index until read of BIO decoded data is complete.
} //Once we're done reading decoded data, BIO_read returns -1 even though there's no error.
BIO_free_all(b64_bio); //Destroys all BIOs in chain, starting with b64 (i.e. the 1st one).
*decoded_bytes = decoded_byte_index;
return base64_decoded; //Returns base-64 decoded data with trailing null terminator.
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -520,13 +520,10 @@ fail:
{
goto end; //Binary
}
char* decoded = base64decode({{{name}}}->valuestring, strlen({{{name}}}->valuestring));
decoded_str_{{{name}}}->data = malloc(strlen(decoded) - 1);
decoded_str_{{{name}}}->data = base64decode({{{name}}}->valuestring, strlen({{{name}}}->valuestring), &decoded_str_{{{name}}}->len);
if (!decoded_str_{{{name}}}->data) {
goto end;
}
memcpy(decoded_str_{{{name}}}->data,decoded,(strlen(decoded)-1));
decoded_str_{{{name}}}->len = strlen(decoded) - 1;
{{/isBinary}}
{{#isDate}}
{{^required}}if ({{{name}}}) { {{/required}}
Expand Down