1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-30 13:01:23 +03:00

buffer: Reformat ssh_buffer_get_ssh_string

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Jakub Jelen
2018-09-11 15:55:03 +02:00
committed by Andreas Schneider
parent 03a66b8599
commit 4d09c6dc31

View File

@@ -758,32 +758,37 @@ int ssh_buffer_validate_length(struct ssh_buffer_struct *buffer, size_t len)
* *
* @returns The SSH String, NULL on error. * @returns The SSH String, NULL on error.
*/ */
struct ssh_string_struct *ssh_buffer_get_ssh_string(struct ssh_buffer_struct *buffer) { struct ssh_string_struct *
uint32_t stringlen; ssh_buffer_get_ssh_string(struct ssh_buffer_struct *buffer)
uint32_t hostlen; {
struct ssh_string_struct *str = NULL; uint32_t stringlen;
int rc; uint32_t hostlen;
struct ssh_string_struct *str = NULL;
int rc;
if (ssh_buffer_get_u32(buffer, &stringlen) == 0) { rc = ssh_buffer_get_u32(buffer, &stringlen);
return NULL; if (rc == 0) {
} return NULL;
hostlen = ntohl(stringlen); }
/* verify if there is enough space in buffer to get it */ hostlen = ntohl(stringlen);
rc = ssh_buffer_validate_length(buffer, hostlen); /* verify if there is enough space in buffer to get it */
if (rc != SSH_OK) { rc = ssh_buffer_validate_length(buffer, hostlen);
return NULL; /* it is indeed */ if (rc != SSH_OK) {
} return NULL; /* it is indeed */
str = ssh_string_new(hostlen); }
if (str == NULL) { str = ssh_string_new(hostlen);
return NULL; if (str == NULL) {
} return NULL;
if (ssh_buffer_get_data(buffer, ssh_string_data(str), hostlen) != hostlen) { }
/* should never happen */
SAFE_FREE(str);
return NULL;
}
return str; stringlen = ssh_buffer_get_data(buffer, ssh_string_data(str), hostlen);
if (stringlen != hostlen) {
/* should never happen */
SAFE_FREE(str);
return NULL;
}
return str;
} }
/** /**