fix: Bounds-check read_from_file restores with snprintf - #64
VedantMadane wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Hi and welcome!
In secret_verification() and data_integrity_check(), snprintf and sizeof will work just fine.
However, in read_from_file(), sizeof will not work as you expect because here 'output' is a pointer to the char array, not the array itself. Calling sizeof(output) will return the size of the pointer which on a 32-bit system is just 4 bytes, causing snprintf to always copy at most 3 characters + a nul-terminator.
Instead, you've got to calculate the size to copy first and then pass it into read_from_file() e.g. like this:
read_from_file(const char* file_name, char* output, size_t output_size)
06ce7a2 to
4c1b446
Compare
|
Thank you for the review and explanation! I have updated |
4c1b446 to
01cfa96
Compare
Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
Summary
Bounds-check read_from_file restores with snprintf
Changes
Fixes #34