-
Notifications
You must be signed in to change notification settings - Fork 88
Handle potential invalid pointer reference for VMCI reply. #973
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 |
---|---|---|
|
@@ -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; | ||
return CONN_FAILURE; | ||
} | ||
|
||
|
@@ -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; | ||
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. 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. 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. Done. |
||
|
||
return host_request(be, &req, ans, ESX_VMCI_CID, port); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,11 @@ func (vmdkCmd EsxVmdkCmd) Run(cmd string, name string, opts map[string]string) ( | |
break | ||
} | ||
|
||
if ans.buf == nil { | ||
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 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 ?
|
||
msg := "VMCI call to ESX failed, returned nil data." | ||
log.Warnf(msg) | ||
return nil, errors.New(msg) | ||
} | ||
response := []byte(C.GoString(ans.buf)) | ||
C.free(unsafe.Pointer(ans.buf)) | ||
err = unmarshalError(response) | ||
|
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.
nit - well, just to be paranoid, it should be
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 :-)
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.
Done.