libssh: path length precaution

Make sure the string is non-zero before indexing it -1. Right now, the
path is always non-zero length so this is more for (future) safety
reasons.

Closes #21193
This commit is contained in:
Daniel Stenberg 2026-04-01 15:31:48 +02:00
parent 38b626e790
commit d888a53e14
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2

View file

@ -2029,7 +2029,9 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data,
if(data->state.upload)
myssh_to(data, sshc, SSH_SFTP_UPLOAD_INIT);
else if(sshp) {
if(sshp->path[strlen(sshp->path) - 1] == '/')
size_t path_len = strlen(sshp->path);
if(path_len && sshp->path[path_len - 1] == '/')
myssh_to(data, sshc, SSH_SFTP_READDIR_INIT);
else
myssh_to(data, sshc, SSH_SFTP_DOWNLOAD_INIT);