Commit 6e7f47da authored by James Housley's avatar James Housley
Browse files

If the creation of rsa and rsa_pub fail due to memory, don't try

other authentication methods.  Terminate with a memory error.
parent 277bab0c
Loading
Loading
Loading
Loading
+18 −16
Original line number Original line Diff line number Diff line
@@ -385,34 +385,36 @@ static CURLcode ssh_statemach_act(struct connectdata *conn)
        else if (home)
        else if (home)
          sshc->rsa_pub = aprintf("%s/.ssh/id_dsa.pub", home);
          sshc->rsa_pub = aprintf("%s/.ssh/id_dsa.pub", home);
        
        
        if (sshc->rsa_pub == NULL) {
          curl_free(home);
          state(conn, SSH_SESSION_FREE);
          sshc->actualCode = CURLE_OUT_OF_MEMORY;
          break;
        }

        if (data->set.ssh_private_key)
        if (data->set.ssh_private_key)
          sshc->rsa = aprintf("%s", data->set.ssh_private_key);
          sshc->rsa = aprintf("%s", data->set.ssh_private_key);
        else if (home)
        else if (home)
          sshc->rsa = aprintf("%s/.ssh/id_dsa", home);
          sshc->rsa = aprintf("%s/.ssh/id_dsa", home);


        if (sshc->rsa == NULL) {
          curl_free(home);
          curl_free(sshc->rsa_pub);
          state(conn, SSH_SESSION_FREE);
          sshc->actualCode = CURLE_OUT_OF_MEMORY;
          break;
        }

        sshc->passphrase = data->set.key_passwd;
        sshc->passphrase = data->set.key_passwd;
        if (!sshc->passphrase)
        if (!sshc->passphrase)
          sshc->passphrase = "";
          sshc->passphrase = "";


        curl_free(home);
        curl_free(home);


        if (sshc->rsa_pub) {
        infof(conn->data, "Using ssh public key file %s\n", sshc->rsa_pub);
        infof(conn->data, "Using ssh public key file %s\n", sshc->rsa_pub);
        }
        if (sshc->rsa) {
        infof(conn->data, "Using ssh private key file %s\n", sshc->rsa);
        infof(conn->data, "Using ssh private key file %s\n", sshc->rsa);
        }


        if (sshc->rsa_pub && sshc->rsa) {
        state(conn, SSH_AUTH_PKEY);
        state(conn, SSH_AUTH_PKEY);
        } else {
          /* One or both aprint()'s might have failed,
             move on to password authentication */
          curl_free(sshc->rsa_pub);
          curl_free(sshc->rsa);

          state(conn, SSH_AUTH_PASS_INIT);
        }
      } else {
      } else {
        state(conn, SSH_AUTH_PASS_INIT);
        state(conn, SSH_AUTH_PASS_INIT);
      }
      }