mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 10:40:27 +09:00
sftp: Use ssh_buffer_pack() in sftp_readlink()
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
32
src/sftp.c
32
src/sftp.c
@@ -2616,8 +2616,7 @@ char *sftp_readlink(sftp_session sftp, const char *path)
|
|||||||
{
|
{
|
||||||
sftp_status_message status = NULL;
|
sftp_status_message status = NULL;
|
||||||
sftp_message msg = NULL;
|
sftp_message msg = NULL;
|
||||||
ssh_string path_s = NULL;
|
ssh_string link_s;
|
||||||
ssh_string link_s = NULL;
|
|
||||||
ssh_buffer buffer;
|
ssh_buffer buffer;
|
||||||
char *lnk;
|
char *lnk;
|
||||||
uint32_t ignored;
|
uint32_t ignored;
|
||||||
@@ -2642,38 +2641,23 @@ char *sftp_readlink(sftp_session sftp, const char *path)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
path_s = ssh_string_from_char(path);
|
id = sftp_get_new_id(sftp);
|
||||||
if (path_s == NULL) {
|
|
||||||
ssh_set_error_oom(sftp->session);
|
|
||||||
ssh_buffer_free(buffer);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = ssh_buffer_allocate_size(buffer,
|
rc = ssh_buffer_pack(buffer,
|
||||||
sizeof(uint32_t) * 2 +
|
"ds",
|
||||||
ssh_string_len(path_s));
|
id,
|
||||||
|
path);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
ssh_set_error_oom(sftp->session);
|
ssh_set_error_oom(sftp->session);
|
||||||
ssh_buffer_free(buffer);
|
ssh_buffer_free(buffer);
|
||||||
ssh_string_free(path_s);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
id = sftp_get_new_id(sftp);
|
rc = sftp_packet_write(sftp, SSH_FXP_READLINK, buffer);
|
||||||
if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
|
|
||||||
ssh_buffer_add_ssh_string(buffer, path_s) < 0) {
|
|
||||||
ssh_set_error_oom(sftp->session);
|
|
||||||
ssh_buffer_free(buffer);
|
ssh_buffer_free(buffer);
|
||||||
ssh_string_free(path_s);
|
if (rc < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (sftp_packet_write(sftp, SSH_FXP_READLINK, buffer) < 0) {
|
|
||||||
ssh_buffer_free(buffer);
|
|
||||||
ssh_string_free(path_s);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
ssh_buffer_free(buffer);
|
|
||||||
ssh_string_free(path_s);
|
|
||||||
|
|
||||||
while (msg == NULL) {
|
while (msg == NULL) {
|
||||||
if (sftp_read_and_dispatch(sftp) < 0) {
|
if (sftp_read_and_dispatch(sftp) < 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user