virauth: Verify virConnectAuth::cb is set in virAuthGetPasswordPath()

Simirarly to virAuthGetUsernamePath() check whether callback used
to collect credentials is actually set before calling it. This
bug is easily reproducible, for instance as:

  int credtype[] = { VIR_CRED_PASSPHRASE };
  virConnectPtr conn = virConnectOpenAuth("esx://root@example.com/",
                                          &(virConnectAuth){
                                          .credtype = credtype,
                                          .ncredtype = 1,
                                          .cb = NULL
                                          },
                                          0);

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik committed 2026-05-18 15:00:57 +02:00
1 parent f8511b6417
commit 4817d1003b
1 file changed
+6
+6
View File
@@ -229,6 +229,12 @@ virAuthGetPasswordPath(const char *path,
return NULL;
}
if (!auth->cb) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("Missing authentication callback"));
return NULL;
}
prompt = g_strdup_printf(_("Enter %1$s's password for %2$s"), username, hostname);
if (!(cred = virAuthAskCredential(auth, prompt, false)))