summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2023-05-15 11:21:28 +0200
committerFelix Fietkau <nbd@nbd.name>2023-05-27 08:00:26 +0200
commit29edb011caf15d39511a5c13ac7a79ed6535d1e0 (patch)
tree799eb5a00915b8c1bbbf13062b8a5e7e7be5194d /lib
parent15f1a669e8e22be119e5e0f93a0665ccbaecb5e6 (diff)
ubus: add support for strings containing null bytes
When converting ucode strings to blobmsg, use blobmsg_add_field in order to explicltly pass the length of the data. In the other direction, use ucv_string_new_length based on the attribute length. Signed-off-by: Felix Fietkau <nbd@nbd.name>
Diffstat (limited to 'lib')
-rw-r--r--lib/ubus.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/ubus.c b/lib/ubus.c
index 085802b..b83e628 100644
--- a/lib/ubus.c
+++ b/lib/ubus.c
@@ -393,7 +393,7 @@ blob_to_ucv(uc_vm_t *vm, struct blob_attr *attr, bool table, const char **name)
return ucv_double_new(v.d);
case BLOBMSG_TYPE_STRING:
- return ucv_string_new(data);
+ return ucv_string_new_length(data, len - 1);
case BLOBMSG_TYPE_ARRAY:
return blob_array_to_ucv(vm, data, len, false);
@@ -444,7 +444,8 @@ ucv_to_blob(const char *name, uc_value_t *val, struct blob_buf *blob)
break;
case UC_STRING:
- blobmsg_add_string(blob, name, ucv_string_get(val));
+ blobmsg_add_field(blob, BLOBMSG_TYPE_STRING, name,
+ ucv_string_get(val), ucv_string_length(val) + 1);
break;
case UC_ARRAY: