diff options
author | Jakub Jelen <jjelen@redhat.com> | 2018-09-11 15:55:03 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2018-09-17 16:39:38 +0200 |
commit | 4d09c6dc315a068a3aa27067f7f0d7654bb6f3fc (patch) | |
tree | aff1309950744ed2d16cc1362a56f7cc3f4593d3 | |
parent | 03a66b859976fea8f9f2097bce14715cefd62d41 (diff) | |
download | libssh-4d09c6dc315a068a3aa27067f7f0d7654bb6f3fc.tar.gz libssh-4d09c6dc315a068a3aa27067f7f0d7654bb6f3fc.tar.xz libssh-4d09c6dc315a068a3aa27067f7f0d7654bb6f3fc.zip |
buffer: Reformat ssh_buffer_get_ssh_string
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r-- | src/buffer.c | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/src/buffer.c b/src/buffer.c index 32ab9139..f6f397b6 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -758,32 +758,37 @@ int ssh_buffer_validate_length(struct ssh_buffer_struct *buffer, size_t len) * * @returns The SSH String, NULL on error. */ -struct ssh_string_struct *ssh_buffer_get_ssh_string(struct ssh_buffer_struct *buffer) { - uint32_t stringlen; - uint32_t hostlen; - struct ssh_string_struct *str = NULL; - int rc; - - if (ssh_buffer_get_u32(buffer, &stringlen) == 0) { - return NULL; - } - hostlen = ntohl(stringlen); - /* verify if there is enough space in buffer to get it */ - rc = ssh_buffer_validate_length(buffer, hostlen); - if (rc != SSH_OK) { - return NULL; /* it is indeed */ - } - str = ssh_string_new(hostlen); - 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; - } +struct ssh_string_struct * +ssh_buffer_get_ssh_string(struct ssh_buffer_struct *buffer) +{ + uint32_t stringlen; + uint32_t hostlen; + struct ssh_string_struct *str = NULL; + int rc; + + rc = ssh_buffer_get_u32(buffer, &stringlen); + if (rc == 0) { + return NULL; + } + hostlen = ntohl(stringlen); + /* verify if there is enough space in buffer to get it */ + rc = ssh_buffer_validate_length(buffer, hostlen); + if (rc != SSH_OK) { + return NULL; /* it is indeed */ + } + str = ssh_string_new(hostlen); + if (str == NULL) { + return NULL; + } + + stringlen = ssh_buffer_get_data(buffer, ssh_string_data(str), hostlen); + if (stringlen != hostlen) { + /* should never happen */ + SAFE_FREE(str); + return NULL; + } - return str; + return str; } /** |