-
Notifications
You must be signed in to change notification settings - Fork 1
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
Fix memory allocation and error handling in binfile_utils.cpp and prover.cpp #2
base: main
Are you sure you want to change the base?
Conversation
@@ -12,6 +12,11 @@ BinFile::BinFile(const void *fileData, size_t fileSize, std::string _type, uint3 | |||
|
|||
size = fileSize; | |||
addr = malloc(size); | |||
|
|||
if (addr == nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better solution is to use unique_ptr<char[]>, or even better - to not copy the data at all (checkout zi/feedback in my fork).
@@ -24,6 +24,12 @@ static size_t PublicBufferMinSize(size_t count) | |||
return count * 82 + 4; | |||
} | |||
|
|||
/** | |||
* Verifies the given prime numbers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These comments are more noise than useful.
@@ -139,21 +175,21 @@ groth16_prover(const void *zkey_buffer, unsigned long zkey_size, | |||
} catch (std::exception& e) { | |||
|
|||
if (error_msg) { | |||
strncpy(error_msg, e.what(), error_msg_maxsize); | |||
strlcpy(error_msg, e.what(), error_msg_maxsize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error messages are already null terminated, no need to double terminate them. But OK to use them I guess.
I added two checks to ensure no NULL pointer after memory operations, and use of
strlcpy
to ensure null terminated strings on error. I also commented on a couple of functions.