Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/komodo_nSPV.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

if (ptr->json) free (ptr->json);
memset(ptr,0,sizeof(*ptr));
}
}

// useful utility functions
Expand Down
2 changes: 1 addition & 1 deletion src/komodo_nSPV_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

};

#endif // KOMODO_NSPV_DEFSH
2 changes: 2 additions & 0 deletions src/komodo_nSPV_fullnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

memcpy(ptr->json,response.c_str(),response.size());
len+=response.size();
return (len);
Expand All @@ -709,6 +710,7 @@ int32_t NSPV_remoterpc(struct NSPV_remoterpcresp *ptr,char *json,int n)
rpc_result = JSONRPCReplyObj(NullUniValue,JSONRPCError(RPC_PARSE_ERROR, e.what()), jreq.id);
response=rpc_result.write();
}
ptr->json = (char*)malloc(response.size());
memcpy(ptr->json,response.c_str(),response.size());
len+=response.size();
return (len);
Expand Down