Open
Description
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.
- input* is placed to address 3FFEFBE0
- encoded* is placed to address 3FFEFBD0
- so nul-terminator of "encoded" overwrites the first byte of input
- so input seems to be consumed.
Fix is easy:
int base64_enc_len(int plainLen) {
return ((plainLen + 2 - ((plainLen + 2) % 3)) / 3 * 4)+1;
}
Metadata
Metadata
Assignees
Labels
No labels