Skip to content
Snippets Groups Projects
Commit c5bf266d authored by Michal Privoznik's avatar Michal Privoznik
Browse files

secret: Fix passing pointers to libvirt APIs


Inspired by one of previous commits, we can not assume that an
array passed to an API has any items, thus getting its pointer to
pass to C API like this: "&array[0]" may lead to a runtime error.
If that's the case, pass nil instead.

Signed-off-by: default avatarMichal Privoznik <mprivozn@redhat.com>
parent d3cfee65
Branches
Tags
1 merge request!60Fix passing pointers to libvirt APIs
......@@ -176,14 +176,19 @@ func (s *Secret) GetValue(flags uint32) ([]byte, error) {
// See also https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretSetValue
func (s *Secret) SetValue(value []byte, flags uint32) error {
cvalue := make([]C.uchar, len(value))
nvalue := len(value)
cvalue := make([]C.uchar, nvalue)
for i := 0; i < len(value); i++ {
for i := 0; i < nvalue; i++ {
cvalue[i] = C.uchar(value[i])
}
var err C.virError
result := C.virSecretSetValueWrapper(s.ptr, &cvalue[0], C.size_t(len(value)), C.uint(flags), &err)
var cvaluePtr *C.uchar = nil
if nvalue > 0 {
cvaluePtr = &cvalue[0]
}
result := C.virSecretSetValueWrapper(s.ptr, cvaluePtr, C.size_t(nvalue), C.uint(flags), &err)
if result == -1 {
return makeError(&err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment