-
Notifications
You must be signed in to change notification settings - Fork 100
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,8 +185,9 @@ struct NSPV_CCmtxinfo | |
|
||
struct NSPV_remoterpcresp | ||
{ | ||
NSPV_remoterpcresp() { method[0] = '\0'; json = nullptr; } | ||
char method[64]; | ||
char json[11000]; | ||
char *json; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that in some cases, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is a memset to zero NSPV_remoterpcresp after the var decl |
||
}; | ||
|
||
#endif // KOMODO_NSPV_DEFSH |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -688,6 +688,9 @@ 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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. definitely should be checked, thank you |
||
if (ptr->json == nullptr) | ||
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Cannot allocate memory for response"); | ||
memcpy(ptr->json,response.c_str(),response.size()); | ||
len+=response.size(); | ||
return (len); | ||
|
@@ -709,6 +712,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()); // only not a big size error responses are here | ||
memcpy(ptr->json,response.c_str(),response.size()); | ||
len+=response.size(); | ||
return (len); | ||
|
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.
I do not know much of the NSPV code, so take this as food for thought. Would this be better off in a destructor?
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.
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