You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// note input is consumed in this step: it will be empty afterwards
base64_encode(encoded, input, inputLen);
There is no consumption of "input" in base64_encode, is it?
But the input gets consumed.
So problem lies somewhere else.
base64_enc_len( "Hello world" ) returns 16.
And base64 encode result is "SGVsbG8gd29ybGQ=", which is 16 characters, OK?
But this doesn't include terminating \0.
So memory gets overwritten.
input* is placed to address 3FFEFBE0
encoded* is placed to address 3FFEFBD0
so nul-terminator of "encoded" overwrites the first byte of input
There is a commentary in sample:
// note input is consumed in this step: it will be empty afterwards
base64_encode(encoded, input, inputLen);
There is no consumption of "input" in base64_encode, is it?
But the input gets consumed.
So problem lies somewhere else.
base64_enc_len( "Hello world" ) returns 16.
And base64 encode result is "SGVsbG8gd29ybGQ=", which is 16 characters, OK?
But this doesn't include terminating \0.
So memory gets overwritten.
Fix is easy:
int base64_enc_len(int plainLen) {
return ((plainLen + 2 - ((plainLen + 2) % 3)) / 3 * 4)+1;
}
The text was updated successfully, but these errors were encountered: