Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Handle potential invalid pointer reference for VMCI reply. #973

Closed
wants to merge 1 commit into from

Conversation

govint
Copy link
Contributor

@govint govint commented Feb 27, 2017

Added a check for NULL recv. buffer in the Esx_VmdkCmd:Run() method and in VMCI client code added setting the buf pointer to NULL on entry and on recv failures.

@@ -291,6 +291,7 @@ vsock_get_reply(be_sock_id *s, be_request *r, be_answer* a)
ret = recv(s->sock_id, a->buf, b, 0);
if (ret == -1 || ret != b) {
free(a->buf);
a->buf = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - well, just to be paranoid, it should be

   if (a->buf) {
     free(a->buf);
     a->buf = NULL;
  }

I know a->buf is not null (per L286-L289, but just to keep this section easier to read and more resilient to changes above it :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -349,5 +350,7 @@ Vmci_GetReply(int port, const char* json_request, const char* be_name,
req.mlen = strnlen(json_request, MAXBUF) + 1;
req.msg = json_request;

ans->buf = NULL;
Copy link
Contributor

@msterin msterin Feb 27, 2017

Choose a reason for hiding this comment

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

wait, why here? if you want it to be NULL, the right place to change would be changing C.Malloc() to C.Calloc() in esx_vmdkcmd.go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -117,6 +117,11 @@ func (vmdkCmd EsxVmdkCmd) Run(cmd string, name string, opts map[string]string) (
break
}

if ans.buf == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I do no think we can get here in failure case without printing ANY message from the loop above, and the logs did not have any message, so I do not see why this block is needed. Besides, with the changes suggested in this PR this can be impossible, will it ? Besides, in cgo is it ok to compare go.nil with C (unsafe) ans.buf ?

  • if you want to for working on a repro, this makes sense, but for production code it feels not needed

@govint
Copy link
Contributor Author

govint commented Mar 6, 2017

The changes are being tracked via #941, comments are addressed and closing this PR.

@govint govint closed this Mar 6, 2017
@shuklanirdesh82 shuklanirdesh82 deleted the attach-err branch March 23, 2017 23:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants