]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: cmdSetUserSSHKeys: Error early if the file doesn't contain any keys
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 8 Dec 2020 12:42:40 +0000 (13:42 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 8 Dec 2020 13:39:13 +0000 (14:39 +0100)
When removing SSH keys via set-user-sshkeys virsh command, then
files to remove are read from passed file. But when
experimenting, I've passed /dev/null as the file which resulted
in API checks which caught that @keys argument of
virDomainAuthorizedSSHKeysSet() can't be NULL. This is because if
the file is empty then its content is an empty string and thus
the buffer the file was read in to is not NULL.

Long story short, error is reported correctly, but it's not
necessary to go through public API to catch it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/virsh-domain.c

index 6266c7acd257c28ad6edbb39cb7a6f92a2f21a69..befa8d2448c9822abf732c5dd8d2841ea4ec5996 100644 (file)
@@ -14398,6 +14398,10 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *cmd)
             goto cleanup;
 
         nkeys = virStringListLength((const char **) keys);
+        if (nkeys == 0) {
+            vshError(ctl, _("File %s contains no keys"), from);
+            goto cleanup;
+        }
     }
 
     if (virDomainAuthorizedSSHKeysSet(dom, user,