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:
10
src/string.c
10
src/string.c
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user