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

string: Make sure we always have the right byte order.

This commit is contained in:
Andreas Schneider
2011-09-08 19:46:14 +02:00
parent 4a5b72a535
commit 81017b0fc2

View File

@@ -75,7 +75,7 @@ struct ssh_string_struct *ssh_string_new(size_t size) {
*/ */
int ssh_string_fill(struct ssh_string_struct *s, const void *data, size_t len) { int ssh_string_fill(struct ssh_string_struct *s, const void *data, size_t len) {
if ((s == NULL) || (data == NULL) || if ((s == NULL) || (data == NULL) ||
(len == 0) || (len > s->size)) { (len == 0) || (len > ssh_string_len(s))) {
return -1; return -1;
} }
@@ -165,7 +165,7 @@ char *ssh_string_to_char(struct ssh_string_struct *s) {
char *new; char *new;
if (s == NULL || s->data == NULL) if (s == NULL || s->data == NULL)
return NULL; return NULL;
len = ntohl(s->size) + 1; len = ssh_string_len(s) + 1;
new = malloc(len); new = malloc(len);
if (new == NULL) { if (new == NULL) {
@@ -200,12 +200,12 @@ struct ssh_string_struct *ssh_string_copy(struct ssh_string_struct *s) {
return NULL; return NULL;
} }
new = ssh_string_new(s->size); new = ssh_string_new(ssh_string_len(s));
if (new == NULL) { if (new == NULL) {
return NULL; return NULL;
} }
new->size = s->size;
memcpy(new->data, s->data, ntohl(s->size)); memcpy(new->data, s->data, ssh_string_len(s));
return new; return new;
} }