1
1

buffer: do not use ssh_buffer_get_rest_len()

As ssh_buffer_get_len() actually calls ssh_buffer_get_rest_len(), let's
just use the first one. This is a preparatory step for removing
ssh_buffer_get_rest_len().

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
Fabiano Fidêncio 2015-09-25 00:34:42 +02:00
родитель 25707e9752
Коммит 05fd0acf45
19 изменённых файлов: 94 добавлений и 94 удалений

Просмотреть файл

@ -273,7 +273,7 @@ static int agent_talk(struct ssh_session_struct *session,
uint32_t len = 0;
uint8_t payload[1024] = {0};
len = ssh_buffer_get_rest_len(request);
len = ssh_buffer_get_len(request);
SSH_LOG(SSH_LOG_TRACE, "Request length: %u", len);
agent_put_u32(payload, len);
@ -541,7 +541,7 @@ ssh_string ssh_agent_sign_data(ssh_session session,
}
/* Add data */
dlen = ssh_buffer_get_rest_len(data);
dlen = ssh_buffer_get_len(data);
if (ssh_buffer_add_u32(request, htonl(dlen)) < 0) {
ssh_buffer_free(request);
return NULL;

Просмотреть файл

@ -426,7 +426,7 @@ int ssh_buffer_add_buffer(struct ssh_buffer_struct *buffer,
rc = ssh_buffer_add_data(buffer,
ssh_buffer_get(source),
ssh_buffer_get_rest_len(source));
ssh_buffer_get_len(source));
if (rc < 0) {
return -1;
}
@ -460,7 +460,7 @@ void *ssh_buffer_get_begin(struct ssh_buffer_struct *buffer){
*
* @return A pointer to the data from current position.
*
* @see ssh_buffer_get_rest_len()
* @see ssh_buffer_get_len()
*/
void *ssh_buffer_get(struct ssh_buffer_struct *buffer){
return buffer->data + buffer->pos;

Просмотреть файл

@ -547,7 +547,7 @@ SSH_PACKET_CALLBACK(channel_rcv_data){
rest = channel->callbacks->channel_data_function(channel->session,
channel,
ssh_buffer_get(buf),
ssh_buffer_get_rest_len(buf),
ssh_buffer_get_len(buf),
is_stderr,
channel->callbacks->userdata);
if(rest > 0) {
@ -556,7 +556,7 @@ SSH_PACKET_CALLBACK(channel_rcv_data){
}
ssh_buffer_pass_bytes(buf, rest);
}
if (channel->local_window + ssh_buffer_get_rest_len(buf) < WINDOWLIMIT) {
if (channel->local_window + ssh_buffer_get_len(buf) < WINDOWLIMIT) {
if (grow_window(session, channel, 0) < 0) {
return -1;
}
@ -612,9 +612,9 @@ SSH_PACKET_CALLBACK(channel_rcv_close) {
channel->remote_channel);
if ((channel->stdout_buffer &&
ssh_buffer_get_rest_len(channel->stdout_buffer) > 0) ||
ssh_buffer_get_len(channel->stdout_buffer) > 0) ||
(channel->stderr_buffer &&
ssh_buffer_get_rest_len(channel->stderr_buffer) > 0)) {
ssh_buffer_get_len(channel->stderr_buffer) > 0)) {
channel->delayed_close = 1;
} else {
channel->state = SSH_CHANNEL_STATE_CLOSED;
@ -1414,9 +1414,9 @@ int ssh_channel_is_eof(ssh_channel channel) {
return SSH_ERROR;
}
if ((channel->stdout_buffer &&
ssh_buffer_get_rest_len(channel->stdout_buffer) > 0) ||
ssh_buffer_get_len(channel->stdout_buffer) > 0) ||
(channel->stderr_buffer &&
ssh_buffer_get_rest_len(channel->stderr_buffer) > 0)) {
ssh_buffer_get_len(channel->stderr_buffer) > 0)) {
return 0;
}
@ -1541,7 +1541,7 @@ static int channel_request(ssh_channel channel, const char *request,
if (buffer != NULL) {
if (ssh_buffer_add_data(session->out_buffer, ssh_buffer_get(buffer),
ssh_buffer_get_rest_len(buffer)) < 0) {
ssh_buffer_get_len(buffer)) < 0) {
ssh_set_error_oom(session);
goto error;
}
@ -2100,7 +2100,7 @@ static int global_request(ssh_session session, const char *request,
if (buffer != NULL) {
rc = ssh_buffer_add_data(session->out_buffer,
ssh_buffer_get(buffer),
ssh_buffer_get_rest_len(buffer));
ssh_buffer_get_len(buffer));
if (rc < 0) {
ssh_set_error_oom(session);
rc = SSH_ERROR;
@ -2584,7 +2584,7 @@ struct ssh_channel_read_termination_struct {
static int ssh_channel_read_termination(void *s){
struct ssh_channel_read_termination_struct *ctx = s;
if (ssh_buffer_get_rest_len(ctx->buffer) >= ctx->count ||
if (ssh_buffer_get_len(ctx->buffer) >= ctx->count ||
ctx->channel->remote_eof ||
ctx->channel->session->session_state == SSH_SESSION_STATE_ERROR)
return 1;
@ -2681,11 +2681,11 @@ int ssh_channel_read_timeout(ssh_channel channel,
SSH_LOG(SSH_LOG_PACKET,
"Read (%d) buffered : %d bytes. Window: %d",
count,
ssh_buffer_get_rest_len(stdbuf),
ssh_buffer_get_len(stdbuf),
channel->local_window);
if (count > ssh_buffer_get_rest_len(stdbuf) + channel->local_window) {
if (grow_window(session, channel, count - ssh_buffer_get_rest_len(stdbuf)) < 0) {
if (count > ssh_buffer_get_len(stdbuf) + channel->local_window) {
if (grow_window(session, channel, count - ssh_buffer_get_len(stdbuf)) < 0) {
return -1;
}
}
@ -2711,10 +2711,10 @@ int ssh_channel_read_timeout(ssh_channel channel,
if (channel->session->session_state == SSH_SESSION_STATE_ERROR){
return SSH_ERROR;
}
if (channel->remote_eof && ssh_buffer_get_rest_len(stdbuf) == 0) {
if (channel->remote_eof && ssh_buffer_get_len(stdbuf) == 0) {
return 0;
}
len = ssh_buffer_get_rest_len(stdbuf);
len = ssh_buffer_get_len(stdbuf);
/* Read count bytes if len is greater, everything otherwise */
len = (len > count ? count : len);
memcpy(dest, ssh_buffer_get(stdbuf), len);
@ -2818,7 +2818,7 @@ int ssh_channel_poll(ssh_channel channel, int is_stderr){
stdbuf = channel->stderr_buffer;
}
if (ssh_buffer_get_rest_len(stdbuf) == 0 && channel->remote_eof == 0) {
if (ssh_buffer_get_len(stdbuf) == 0 && channel->remote_eof == 0) {
if (channel->session->session_state == SSH_SESSION_STATE_ERROR){
return SSH_ERROR;
}
@ -2827,15 +2827,15 @@ int ssh_channel_poll(ssh_channel channel, int is_stderr){
}
}
if (ssh_buffer_get_rest_len(stdbuf) > 0){
return ssh_buffer_get_rest_len(stdbuf);
if (ssh_buffer_get_len(stdbuf) > 0){
return ssh_buffer_get_len(stdbuf);
}
if (channel->remote_eof) {
return SSH_EOF;
}
return ssh_buffer_get_rest_len(stdbuf);
return ssh_buffer_get_len(stdbuf);
}
/**
@ -2882,7 +2882,7 @@ int ssh_channel_poll_timeout(ssh_channel channel, int timeout, int is_stderr){
rc = SSH_ERROR;
goto end;
}
rc = ssh_buffer_get_rest_len(stdbuf);
rc = ssh_buffer_get_len(stdbuf);
if(rc > 0)
goto end;
if (channel->remote_eof)
@ -2971,8 +2971,8 @@ static int channel_protocol_select(ssh_channel *rchans, ssh_channel *wchans,
ssh_handle_packets(chan->session, SSH_TIMEOUT_NONBLOCKING);
}
if ((chan->stdout_buffer && ssh_buffer_get_rest_len(chan->stdout_buffer) > 0) ||
(chan->stderr_buffer && ssh_buffer_get_rest_len(chan->stderr_buffer) > 0) ||
if ((chan->stdout_buffer && ssh_buffer_get_len(chan->stdout_buffer) > 0) ||
(chan->stderr_buffer && ssh_buffer_get_len(chan->stderr_buffer) > 0) ||
chan->remote_eof) {
rout[j] = chan;
j++;

Просмотреть файл

@ -573,11 +573,11 @@ int ssh_make_sessionid(ssh_session session) {
rc = ssh_buffer_pack(buf,
"dPdPS",
ssh_buffer_get_rest_len(client_hash),
ssh_buffer_get_rest_len(client_hash),
ssh_buffer_get_len(client_hash),
ssh_buffer_get_len(client_hash),
ssh_buffer_get(client_hash),
ssh_buffer_get_rest_len(server_hash),
ssh_buffer_get_rest_len(server_hash),
ssh_buffer_get_len(server_hash),
ssh_buffer_get_len(server_hash),
ssh_buffer_get(server_hash),
session->next_crypto->server_pubkey);
@ -643,7 +643,7 @@ int ssh_make_sessionid(ssh_session session) {
ssh_set_error_oom(session);
goto error;
}
sha1(ssh_buffer_get(buf), ssh_buffer_get_rest_len(buf),
sha1(ssh_buffer_get(buf), ssh_buffer_get_len(buf),
session->next_crypto->secret_hash);
break;
case SSH_KEX_ECDH_SHA2_NISTP256:
@ -655,7 +655,7 @@ int ssh_make_sessionid(ssh_session session) {
ssh_set_error_oom(session);
goto error;
}
sha256(ssh_buffer_get(buf), ssh_buffer_get_rest_len(buf),
sha256(ssh_buffer_get(buf), ssh_buffer_get_len(buf),
session->next_crypto->secret_hash);
break;
}

Просмотреть файл

@ -59,7 +59,7 @@ static z_stream *initcompress(ssh_session session, int level) {
static ssh_buffer gzip_compress(ssh_session session,ssh_buffer source,int level){
z_stream *zout = session->current_crypto->compress_out_ctx;
void *in_ptr = ssh_buffer_get(source);
unsigned long in_size = ssh_buffer_get_rest_len(source);
unsigned long in_size = ssh_buffer_get_len(source);
ssh_buffer dest = NULL;
unsigned char out_buf[BLOCKSIZE] = {0};
unsigned long len;
@ -113,7 +113,7 @@ int compress_buffer(ssh_session session, ssh_buffer buf) {
return -1;
}
if (ssh_buffer_add_data(buf, ssh_buffer_get(dest), ssh_buffer_get_rest_len(dest)) < 0) {
if (ssh_buffer_add_data(buf, ssh_buffer_get(dest), ssh_buffer_get_len(dest)) < 0) {
ssh_buffer_free(dest);
return -1;
}
@ -148,7 +148,7 @@ static z_stream *initdecompress(ssh_session session) {
static ssh_buffer gzip_decompress(ssh_session session, ssh_buffer source, size_t maxlen) {
z_stream *zin = session->current_crypto->compress_in_ctx;
void *in_ptr = ssh_buffer_get(source);
unsigned long in_size = ssh_buffer_get_rest_len(source);
unsigned long in_size = ssh_buffer_get_len(source);
unsigned char out_buf[BLOCKSIZE] = {0};
ssh_buffer dest = NULL;
unsigned long len;
@ -185,7 +185,7 @@ static ssh_buffer gzip_decompress(ssh_session session, ssh_buffer source, size_t
ssh_buffer_free(dest);
return NULL;
}
if (ssh_buffer_get_rest_len(dest) > maxlen){
if (ssh_buffer_get_len(dest) > maxlen){
/* Size of packet exceeded, avoid a denial of service attack */
ssh_buffer_free(dest);
return NULL;
@ -209,7 +209,7 @@ int decompress_buffer(ssh_session session,ssh_buffer buf, size_t maxlen){
return -1;
}
if (ssh_buffer_add_data(buf, ssh_buffer_get(dest), ssh_buffer_get_rest_len(dest)) < 0) {
if (ssh_buffer_add_data(buf, ssh_buffer_get(dest), ssh_buffer_get_len(dest)) < 0) {
ssh_buffer_free(dest);
return -1;
}

Просмотреть файл

@ -264,14 +264,14 @@ static int check_public_key(ssh_session session, char **tokens) {
return -1;
}
if (ssh_buffer_get_rest_len(pubkey_buffer) != ssh_string_len(pubkey)) {
if (ssh_buffer_get_len(pubkey_buffer) != ssh_string_len(pubkey)) {
ssh_buffer_free(pubkey_buffer);
return 0;
}
/* now test that they are identical */
if (memcmp(ssh_buffer_get(pubkey_buffer), ssh_string_data(pubkey),
ssh_buffer_get_rest_len(pubkey_buffer)) != 0) {
ssh_buffer_get_len(pubkey_buffer)) != 0) {
ssh_buffer_free(pubkey_buffer);
return 0;
}
@ -340,7 +340,7 @@ static int match_hashed_host(const char *host, const char *sourcehash)
return 0;
}
mac = hmac_init(ssh_buffer_get(salt), ssh_buffer_get_rest_len(salt), SSH_HMAC_SHA1);
mac = hmac_init(ssh_buffer_get(salt), ssh_buffer_get_len(salt), SSH_HMAC_SHA1);
if (mac == NULL) {
ssh_buffer_free(salt);
ssh_buffer_free(hash);
@ -351,7 +351,7 @@ static int match_hashed_host(const char *host, const char *sourcehash)
hmac_update(mac, host, strlen(host));
hmac_final(mac, buffer, &size);
if (size == ssh_buffer_get_rest_len(hash) &&
if (size == ssh_buffer_get_len(hash) &&
memcmp(buffer, ssh_buffer_get(hash), size) == 0) {
match = 1;
} else {

Просмотреть файл

@ -787,7 +787,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
sig_blob,
msg->auth_request.pubkey,
ssh_buffer_get(digest),
ssh_buffer_get_rest_len(digest));
ssh_buffer_get_len(digest));
ssh_string_free(sig_blob);
ssh_buffer_free(digest);
if (rc < 0) {

Просмотреть файл

@ -253,7 +253,7 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
* Decrypt the rest of the packet (blocksize bytes already
* have been decrypted)
*/
uint32_t buffer_len = ssh_buffer_get_rest_len(session->in_buffer);
uint32_t buffer_len = ssh_buffer_get_len(session->in_buffer);
/* The following check avoids decrypting zero bytes */
if (buffer_len > blocksize) {
@ -290,28 +290,28 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
goto error;
}
if (padding > ssh_buffer_get_rest_len(session->in_buffer)) {
if (padding > ssh_buffer_get_len(session->in_buffer)) {
ssh_set_error(session,
SSH_FATAL,
"Invalid padding: %d (%d left)",
padding,
ssh_buffer_get_rest_len(session->in_buffer));
ssh_buffer_get_len(session->in_buffer));
goto error;
}
ssh_buffer_pass_bytes_end(session->in_buffer, padding);
compsize = ssh_buffer_get_rest_len(session->in_buffer);
compsize = ssh_buffer_get_len(session->in_buffer);
#ifdef WITH_ZLIB
if (session->current_crypto
&& session->current_crypto->do_compress_in
&& ssh_buffer_get_rest_len(session->in_buffer) > 0) {
&& ssh_buffer_get_len(session->in_buffer) > 0) {
rc = decompress_buffer(session, session->in_buffer,MAX_PACKET_LEN);
if (rc < 0) {
goto error;
}
}
#endif /* WITH_ZLIB */
payloadsize = ssh_buffer_get_rest_len(session->in_buffer);
payloadsize = ssh_buffer_get_len(session->in_buffer);
session->recv_seq++;
if (session->raw_counter != NULL) {
session->raw_counter->in_bytes += payloadsize;
@ -508,7 +508,7 @@ static int ssh_packet_write(ssh_session session) {
rc=ssh_socket_write(session->socket,
ssh_buffer_get(session->out_buffer),
ssh_buffer_get_rest_len(session->out_buffer));
ssh_buffer_get_len(session->out_buffer));
return rc;
}
@ -518,7 +518,7 @@ static int packet_send2(ssh_session session) {
session->current_crypto->out_cipher->blocksize : 8);
enum ssh_hmac_e hmac_type = (session->current_crypto ?
session->current_crypto->out_hmac : session->next_crypto->out_hmac);
uint32_t currentlen = ssh_buffer_get_rest_len(session->out_buffer);
uint32_t currentlen = ssh_buffer_get_len(session->out_buffer);
unsigned char *hmac = NULL;
char padstring[32] = { 0 };
int rc = SSH_ERROR;
@ -531,11 +531,11 @@ static int packet_send2(ssh_session session) {
#ifdef WITH_ZLIB
if (session->current_crypto
&& session->current_crypto->do_compress_out
&& ssh_buffer_get_rest_len(session->out_buffer)) {
&& ssh_buffer_get_len(session->out_buffer)) {
if (compress_buffer(session,session->out_buffer) < 0) {
goto error;
}
currentlen = ssh_buffer_get_rest_len(session->out_buffer);
currentlen = ssh_buffer_get_len(session->out_buffer);
}
#endif /* WITH_ZLIB */
compsize = currentlen;
@ -563,12 +563,12 @@ static int packet_send2(ssh_session session) {
#ifdef WITH_PCAP
if(session->pcap_ctx){
ssh_pcap_context_write(session->pcap_ctx,SSH_PCAP_DIR_OUT,
ssh_buffer_get(session->out_buffer),ssh_buffer_get_rest_len(session->out_buffer)
,ssh_buffer_get_rest_len(session->out_buffer));
ssh_buffer_get(session->out_buffer),ssh_buffer_get_len(session->out_buffer)
,ssh_buffer_get_len(session->out_buffer));
}
#endif
hmac = ssh_packet_encrypt(session, ssh_buffer_get(session->out_buffer),
ssh_buffer_get_rest_len(session->out_buffer));
ssh_buffer_get_len(session->out_buffer));
if (hmac) {
rc = ssh_buffer_add_data(session->out_buffer, hmac, hmac_digest_len(hmac_type));
if (rc < 0) {

Просмотреть файл

@ -185,7 +185,7 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
ssh_buffer_get_len(session->in_buffer));
#endif
SSH_LOG(SSH_LOG_PACKET, "%d bytes padding", padding);
if(((len + padding) != ssh_buffer_get_rest_len(session->in_buffer)) ||
if(((len + padding) != ssh_buffer_get_len(session->in_buffer)) ||
((len + padding) < sizeof(uint32_t))) {
SSH_LOG(SSH_LOG_RARE, "no crc32 in packet");
ssh_set_error(session, SSH_FATAL, "no crc32 in packet");

Просмотреть файл

@ -164,7 +164,7 @@ int ssh_packet_hmac_verify(ssh_session session, ssh_buffer buffer,
seq = htonl(session->recv_seq);
hmac_update(ctx, (unsigned char *) &seq, sizeof(uint32_t));
hmac_update(ctx, ssh_buffer_get(buffer), ssh_buffer_get_rest_len(buffer));
hmac_update(ctx, ssh_buffer_get(buffer), ssh_buffer_get_len(buffer));
hmac_final(ctx, hmacbuf, &len);
#ifdef DEBUG_CRYPTO

Просмотреть файл

@ -144,7 +144,7 @@ static int ssh_pcap_file_write(ssh_pcap_file pcap, ssh_buffer packet){
uint32_t len;
if(pcap == NULL || pcap->output==NULL)
return SSH_ERROR;
len=ssh_buffer_get_rest_len(packet);
len=ssh_buffer_get_len(packet);
err=fwrite(ssh_buffer_get(packet),len,1,pcap->output);
if(err<0)
return SSH_ERROR;
@ -171,7 +171,7 @@ int ssh_pcap_file_write_packet(ssh_pcap_file pcap, ssh_buffer packet, uint32_t o
if (err < 0) {
goto error;
}
err = ssh_buffer_add_u32(header,htonl(ssh_buffer_get_rest_len(packet)));
err = ssh_buffer_add_u32(header,htonl(ssh_buffer_get_len(packet)));
if (err < 0) {
goto error;
}

Просмотреть файл

@ -1467,13 +1467,13 @@ int ssh_pki_export_signature_blob(const ssh_signature sig,
return SSH_ERROR;
}
str = ssh_string_new(ssh_buffer_get_rest_len(buf));
str = ssh_string_new(ssh_buffer_get_len(buf));
if (str == NULL) {
ssh_buffer_free(buf);
return SSH_ERROR;
}
ssh_string_fill(str, ssh_buffer_get(buf), ssh_buffer_get_rest_len(buf));
ssh_string_fill(str, ssh_buffer_get(buf), ssh_buffer_get_len(buf));
ssh_buffer_free(buf);
*sig_blob = str;
@ -1629,7 +1629,7 @@ ssh_string ssh_pki_do_sign(ssh_session session,
}
evp_update(ctx, session_id, ssh_string_len(session_id) + 4);
evp_update(ctx, ssh_buffer_get(sigbuf), ssh_buffer_get_rest_len(sigbuf));
evp_update(ctx, ssh_buffer_get(sigbuf), ssh_buffer_get_len(sigbuf));
evp_final(ctx, ehash, &elen);
#ifdef DEBUG_CRYPTO
@ -1651,7 +1651,7 @@ ssh_string ssh_pki_do_sign(ssh_session session,
rc = ssh_buffer_pack(buf,
"SP",
session_id,
ssh_buffer_get_rest_len(sigbuf), ssh_buffer_get(sigbuf));
ssh_buffer_get_len(sigbuf), ssh_buffer_get(sigbuf));
if (rc != SSH_OK) {
ssh_string_free(session_id);
ssh_buffer_free(buf);
@ -1673,7 +1673,7 @@ ssh_string ssh_pki_do_sign(ssh_session session,
}
sha1_update(ctx, session_id, ssh_string_len(session_id) + 4);
sha1_update(ctx, ssh_buffer_get(sigbuf), ssh_buffer_get_rest_len(sigbuf));
sha1_update(ctx, ssh_buffer_get(sigbuf), ssh_buffer_get_len(sigbuf));
sha1_final(hash, ctx);
#ifdef DEBUG_CRYPTO

Просмотреть файл

@ -387,7 +387,7 @@ ssh_key ssh_pki_openssh_privkey_import(const char *text_key,
comment = ssh_buffer_get_ssh_string(privkey_buffer);
SAFE_FREE(comment);
/* verify that the remaining data is correct padding */
for (i=1; ssh_buffer_get_rest_len(privkey_buffer) > 0; ++i){
for (i=1; ssh_buffer_get_len(privkey_buffer) > 0; ++i){
ssh_buffer_get_u8(privkey_buffer, &padding);
if (padding != i){
ssh_key_free(key);

Просмотреть файл

@ -1034,12 +1034,12 @@ ssh_string pki_publickey_to_blob(const ssh_key key)
goto fail;
}
str = ssh_string_new(ssh_buffer_get_rest_len(buffer));
str = ssh_string_new(ssh_buffer_get_len(buffer));
if (str == NULL) {
goto fail;
}
rc = ssh_string_fill(str, ssh_buffer_get(buffer), ssh_buffer_get_rest_len(buffer));
rc = ssh_string_fill(str, ssh_buffer_get(buffer), ssh_buffer_get_len(buffer));
if (rc < 0) {
goto fail;
}
@ -1238,13 +1238,13 @@ ssh_string pki_signature_to_blob(const ssh_signature sig)
return NULL;
}
sig_blob = ssh_string_new(ssh_buffer_get_rest_len(b));
sig_blob = ssh_string_new(ssh_buffer_get_len(b));
if (sig_blob == NULL) {
ssh_buffer_free(b);
return NULL;
}
ssh_string_fill(sig_blob, ssh_buffer_get(b), ssh_buffer_get_rest_len(b));
ssh_string_fill(sig_blob, ssh_buffer_get(b), ssh_buffer_get_len(b));
ssh_buffer_free(b);
break;
}

Просмотреть файл

@ -1300,12 +1300,12 @@ ssh_string pki_publickey_to_blob(const ssh_key key)
goto fail;
}
str = ssh_string_new(ssh_buffer_get_rest_len(buffer));
str = ssh_string_new(ssh_buffer_get_len(buffer));
if (str == NULL) {
goto fail;
}
rc = ssh_string_fill(str, ssh_buffer_get(buffer), ssh_buffer_get_rest_len(buffer));
rc = ssh_string_fill(str, ssh_buffer_get(buffer), ssh_buffer_get_len(buffer));
if (rc < 0) {
goto fail;
}

Просмотреть файл

@ -282,20 +282,20 @@ int sftp_packet_write(sftp_session sftp, uint8_t type, ssh_buffer payload){
return -1;
}
size = htonl(ssh_buffer_get_rest_len(payload));
size = htonl(ssh_buffer_get_len(payload));
if (ssh_buffer_prepend_data(payload, &size, sizeof(uint32_t)) < 0) {
ssh_set_error_oom(sftp->session);
return -1;
}
size = ssh_channel_write(sftp->channel, ssh_buffer_get(payload),
ssh_buffer_get_rest_len(payload));
ssh_buffer_get_len(payload));
if (size < 0) {
return -1;
} else if((uint32_t) size != ssh_buffer_get_rest_len(payload)) {
} else if((uint32_t) size != ssh_buffer_get_len(payload)) {
SSH_LOG(SSH_LOG_PACKET,
"Had to write %d bytes, wrote only %d",
ssh_buffer_get_rest_len(payload),
ssh_buffer_get_len(payload),
size);
}
@ -461,7 +461,7 @@ static sftp_message sftp_get_message(sftp_packet packet) {
msg->packet_type);
if (ssh_buffer_add_data(msg->payload, ssh_buffer_get(packet->payload),
ssh_buffer_get_rest_len(packet->payload)) < 0) {
ssh_buffer_get_len(packet->payload)) < 0) {
ssh_set_error_oom(sftp->session);
sftp_message_free(msg);
return NULL;
@ -1968,7 +1968,7 @@ ssize_t sftp_write(sftp_file file, const void *buf, size_t count) {
ssh_buffer_free(buffer);
return -1;
}
packetlen=ssh_buffer_get_rest_len(buffer);
packetlen=ssh_buffer_get_len(buffer);
len = sftp_packet_write(file->sftp, SSH_FXP_WRITE, buffer);
ssh_buffer_free(buffer);
if (len < 0) {

Просмотреть файл

@ -66,7 +66,7 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
msg->complete_message = ssh_buffer_new();
ssh_buffer_add_data(msg->complete_message,
ssh_buffer_get(payload),
ssh_buffer_get_rest_len(payload));
ssh_buffer_get_len(payload));
ssh_buffer_get_u32(payload, &msg->id);
@ -378,7 +378,7 @@ int sftp_reply_names(sftp_client_message msg) {
if (ssh_buffer_add_u32(out, msg->id) < 0 ||
ssh_buffer_add_u32(out, htonl(msg->attr_num)) < 0 ||
ssh_buffer_add_data(out, ssh_buffer_get(msg->attrbuf),
ssh_buffer_get_rest_len(msg->attrbuf)) < 0 ||
ssh_buffer_get_len(msg->attrbuf)) < 0 ||
sftp_packet_write(msg->sftp, SSH_FXP_NAME, out) < 0) {
ssh_buffer_free(out);
ssh_buffer_free(msg->attrbuf);

Просмотреть файл

@ -291,7 +291,7 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd,
if (s->callbacks && s->callbacks->data) {
do {
r = s->callbacks->data(ssh_buffer_get(s->in_buffer),
ssh_buffer_get_rest_len(s->in_buffer),
ssh_buffer_get_len(s->in_buffer),
s->callbacks->userdata);
ssh_buffer_pass_bytes(s->in_buffer, r);
} while ((r > 0) && (s->state == SSH_SOCKET_CONNECTED));
@ -330,7 +330,7 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd,
}
/* If buffered data is pending, write it */
if (ssh_buffer_get_rest_len(s->out_buffer) > 0) {
if (ssh_buffer_get_len(s->out_buffer) > 0) {
ssh_socket_nonblocking_flush(s);
} else if (s->callbacks && s->callbacks->controlflow) {
/* Otherwise advertise the upper level that write can be done */
@ -650,7 +650,7 @@ int ssh_socket_nonblocking_flush(ssh_socket s) {
return SSH_ERROR;
}
len = ssh_buffer_get_rest_len(s->out_buffer);
len = ssh_buffer_get_len(s->out_buffer);
if (!s->write_wontblock && s->poll_out && len > 0) {
/* force the poll system to catch pollout events */
ssh_poll_add_events(s->poll_out, POLLOUT);
@ -681,7 +681,7 @@ int ssh_socket_nonblocking_flush(ssh_socket s) {
}
/* Is there some data pending? */
len = ssh_buffer_get_rest_len(s->out_buffer);
len = ssh_buffer_get_len(s->out_buffer);
if (s->poll_out && len > 0) {
/* force the poll system to catch pollout events */
ssh_poll_add_events(s->poll_out, POLLOUT);
@ -721,7 +721,7 @@ int ssh_socket_data_writable(ssh_socket s) {
int ssh_socket_buffered_write_bytes(ssh_socket s){
if(s==NULL || s->out_buffer == NULL)
return 0;
return ssh_buffer_get_rest_len(s->out_buffer);
return ssh_buffer_get_len(s->out_buffer);
}

Просмотреть файл

@ -36,8 +36,8 @@ static void torture_growing_buffer(void **state) {
for(i=0;i<LIMIT;++i){
ssh_buffer_add_data(buffer,"A",1);
if(buffer->used >= 128){
if(ssh_buffer_get_rest_len(buffer) * 2 < buffer->allocated){
assert_true(ssh_buffer_get_rest_len(buffer) * 2 >= buffer->allocated);
if(ssh_buffer_get_len(buffer) * 2 < buffer->allocated){
assert_true(ssh_buffer_get_len(buffer) * 2 >= buffer->allocated);
}
}
}
@ -58,8 +58,8 @@ static void torture_growing_buffer_shifting(void **state) {
ssh_buffer_get_u8(buffer,&c);
ssh_buffer_add_data(buffer,"A",1);
if(buffer->used >= 128){
if(ssh_buffer_get_rest_len(buffer) * 4 < buffer->allocated){
assert_true(ssh_buffer_get_rest_len(buffer) * 4 >= buffer->allocated);
if(ssh_buffer_get_len(buffer) * 4 < buffer->allocated){
assert_true(ssh_buffer_get_len(buffer) * 4 >= buffer->allocated);
return;
}
}
@ -74,25 +74,25 @@ static void torture_buffer_prepend(void **state) {
uint32_t v;
ssh_buffer_add_data(buffer,"abcdef",6);
ssh_buffer_prepend_data(buffer,"xyz",3);
assert_int_equal(ssh_buffer_get_rest_len(buffer),9);
assert_int_equal(ssh_buffer_get_len(buffer),9);
assert_memory_equal(ssh_buffer_get(buffer), "xyzabcdef", 9);
/* Now remove 4 bytes and see if we can replace them */
ssh_buffer_get_u32(buffer,&v);
assert_int_equal(ssh_buffer_get_rest_len(buffer),5);
assert_int_equal(ssh_buffer_get_len(buffer),5);
assert_memory_equal(ssh_buffer_get(buffer), "bcdef", 5);
ssh_buffer_prepend_data(buffer,"aris",4);
assert_int_equal(ssh_buffer_get_rest_len(buffer),9);
assert_int_equal(ssh_buffer_get_len(buffer),9);
assert_memory_equal(ssh_buffer_get(buffer), "arisbcdef", 9);
/* same thing but we add 5 bytes now */
ssh_buffer_get_u32(buffer,&v);
assert_int_equal(ssh_buffer_get_rest_len(buffer),5);
assert_int_equal(ssh_buffer_get_len(buffer),5);
assert_memory_equal(ssh_buffer_get(buffer), "bcdef", 5);
ssh_buffer_prepend_data(buffer,"12345",5);
assert_int_equal(ssh_buffer_get_rest_len(buffer),10);
assert_int_equal(ssh_buffer_get_len(buffer),10);
assert_memory_equal(ssh_buffer_get(buffer), "12345bcdef", 10);
}
@ -155,7 +155,7 @@ static void torture_ssh_buffer_add_format(void **state) {
rc=ssh_buffer_pack(buffer, "bwdqSsPt",b,w,d,q,s,"rocks",7,"So much","Fun!");
assert_int_equal(rc, SSH_OK);
len = ssh_buffer_get_rest_len(buffer);
len = ssh_buffer_get_len(buffer);
assert_int_equal(len, sizeof(verif) - 1);
assert_memory_equal(ssh_buffer_get(buffer), verif, sizeof(verif) -1);
@ -199,7 +199,7 @@ static void torture_ssh_buffer_get_format(void **state) {
assert_true(s2 != NULL);
assert_memory_equal(s2, "So much", 7);
len = ssh_buffer_get_rest_len(buffer);
len = ssh_buffer_get_len(buffer);
assert_int_equal(len, 0);
SAFE_FREE(s);
SAFE_FREE(s1);