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

Fix memory allocation and error handling in binfile_utils.cpp and prover.cpp #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zi0Black
Copy link

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.

@@ -12,6 +12,11 @@ BinFile::BinFile(const void *fileData, size_t fileSize, std::string _type, uint3

size = fileSize;
addr = malloc(size);

if (addr == nullptr) {
Copy link
Collaborator

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.
Copy link
Collaborator

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);
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants