1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

virsh: cmdSecretGetValue: Use virSecureErase instead of VIR_DISPOSE_N

Switch the secret value to 'g_autofree' for handling of the memory and
clear it out using virSecureErase.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Peter Krempa 2021-02-01 14:09:01 +01:00
parent ee88bce43d
commit e6195ed80c

View File

@ -303,7 +303,7 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd)
{ {
g_autoptr(virshSecret) secret = NULL; g_autoptr(virshSecret) secret = NULL;
VIR_AUTODISPOSE_STR base64 = NULL; VIR_AUTODISPOSE_STR base64 = NULL;
unsigned char *value; g_autofree unsigned char *value = NULL;
size_t value_size; size_t value_size;
bool plain = vshCommandOptBool(cmd, "plain"); bool plain = vshCommandOptBool(cmd, "plain");
@ -315,7 +315,7 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd)
if (plain) { if (plain) {
if (fwrite(value, 1, value_size, stdout) != value_size) { if (fwrite(value, 1, value_size, stdout) != value_size) {
VIR_DISPOSE_N(value, value_size); virSecureErase(value, value_size);
vshError(ctl, "failed to write secret"); vshError(ctl, "failed to write secret");
return false; return false;
} }
@ -325,7 +325,7 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd)
vshPrint(ctl, "%s", base64); vshPrint(ctl, "%s", base64);
} }
VIR_DISPOSE_N(value, value_size); virSecureErase(value, value_size);
return true; return true;
} }