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

Nspv json response buffer fix #530

Closed
wants to merge 3 commits into from

Conversation

dimxy
Copy link
Collaborator

@dimxy dimxy commented Feb 3, 2022

No description provided.

@dimxy dimxy requested review from Alrighttt and DeckerSU February 4, 2022 08:37
@@ -688,6 +688,7 @@ int32_t NSPV_remoterpc(struct NSPV_remoterpcresp *ptr,char *json,int n)
{
rpc_result = JSONRPCReplyObj(result, NullUniValue, jreq.id);
response=rpc_result.write();
ptr->json = (char*)malloc(response.size());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it possible that response.size() could be a large number. Should there be checks to assure that the malloc here (and below) did not return nullptr?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely should be checked, thank you

@@ -441,8 +441,10 @@ int32_t NSPV_rwremoterpcresp(int32_t rwflag,uint8_t *serialized,struct NSPV_remo

void NSPV_remoterpc_purge(struct NSPV_remoterpcresp *ptr)
{
if ( ptr != 0 )
if ( ptr != 0 ) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know much of the NSPV code, so take this as food for thought. Would this be better off in a destructor?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally refactored the nspv code and replaced all such read/write functions to CDataStream object, sent it into research-new branch. So eventually all this code will be replaced

Copy link

@jmjatlanta jmjatlanta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that NSPV_rwremoterpcresp is never used to write to the struct, but would be dangerous if it tried to. I suggest either (a) renaming the method and removing the first parameter or (b) asserting if the first parameter is ever a 0.

Also, adding a constructor/destructor to the struct would move the need for the functionality of memset and _purge to a central location.

@@ -186,7 +186,7 @@ struct NSPV_CCmtxinfo
struct NSPV_remoterpcresp
{
char method[64];
char json[11000];
char *json;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that in some cases, json != nullptr. It may be better to explicitly initialize it to nullptr here. This will make _purge method less dangerous.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a memset to zero NSPV_remoterpcresp after the var decl
but just added a constructor to auto init to zeros

@dimxy
Copy link
Collaborator Author

dimxy commented Sep 16, 2022

this PR is in the combined #559 PR

@dimxy dimxy closed this Sep 16, 2022
@dimxy dimxy deleted the nspv-json-resp-fix branch February 6, 2023 07:57
who-biz pushed a commit to who-biz/komodo that referenced this pull request Jul 29, 2024
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