ssh.c: fix realloc() OOM handling

This commit is contained in:
Yang Tse 2011-08-31 18:15:29 +02:00
parent 0b018a0a05
commit 5ea65fbc79
1 changed files with 9 additions and 4 deletions

View File

@ -644,6 +644,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
const char *fingerprint; const char *fingerprint;
#endif /* CURL_LIBSSH2_DEBUG */ #endif /* CURL_LIBSSH2_DEBUG */
const char *host_public_key_md5; const char *host_public_key_md5;
char *new_readdir_line;
int rc = LIBSSH2_ERROR_NONE, i; int rc = LIBSSH2_ERROR_NONE, i;
int err; int err;
int seekerr = CURL_SEEKFUNC_OK; int seekerr = CURL_SEEKFUNC_OK;
@ -1859,10 +1860,13 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
} }
Curl_safefree(sshc->readdir_linkPath); Curl_safefree(sshc->readdir_linkPath);
sshc->readdir_linkPath = NULL; sshc->readdir_linkPath = NULL;
sshc->readdir_line = realloc(sshc->readdir_line,
sshc->readdir_totalLen + 4 + new_readdir_line = realloc(sshc->readdir_line,
sshc->readdir_len); sshc->readdir_totalLen + 4 +
if(!sshc->readdir_line) { sshc->readdir_len);
if(!new_readdir_line) {
Curl_safefree(sshc->readdir_line);
sshc->readdir_line = NULL;
Curl_safefree(sshc->readdir_filename); Curl_safefree(sshc->readdir_filename);
sshc->readdir_filename = NULL; sshc->readdir_filename = NULL;
Curl_safefree(sshc->readdir_longentry); Curl_safefree(sshc->readdir_longentry);
@ -1871,6 +1875,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
sshc->actualcode = CURLE_OUT_OF_MEMORY; sshc->actualcode = CURLE_OUT_OF_MEMORY;
break; break;
} }
sshc->readdir_line = new_readdir_line;
sshc->readdir_currLen += snprintf(sshc->readdir_line + sshc->readdir_currLen += snprintf(sshc->readdir_line +
sshc->readdir_currLen, sshc->readdir_currLen,