summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Darbyshire-Bryant2020-07-19 13:14:12 +0000
committerKevin Darbyshire-Bryant2020-07-19 13:14:12 +0000
commiteadfa26a5cf31e27f551c37c1362983e9db37c4d (patch)
tree21ad43b77f366cf953640dece194808818ce0710
parentd13290b427487bb05581e11875af3bfe74d6da2d (diff)
downloadmdnsd-eadfa26a5cf31e27f551c37c1362983e9db37c4d.tar.gz
service.c: fix build on gcc 10
Resolve error: /Users/kevin/wrt/build_dir/target-x86_64_musl/umdns-2020-06-08-d13290b4/service.c: In function 'service_load_blob': /Users/kevin/wrt/build_dir/target-x86_64_musl/umdns-2020-06-08-d13290b4/service.c:240:10: error: 'strcpy' offset 6 from the object at 'b' is out of the bounds of referenced subobject 'name' with type 'uint8_t[]' {aka 'unsigned char[]'} at offset 6 [-Werror=array-bounds] 240 | s->id = strcpy(d_id, blobmsg_name(b)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /Users/kevin/wrt/staging_dir/target-x86_64_musl/usr/include/libubus.h:23, from /Users/kevin/wrt/build_dir/target-x86_64_musl/umdns-2020-06-08-d13290b4/service.c:23: /Users/kevin/wrt/staging_dir/target-x86_64_musl/usr/include/libubox/blobmsg.h:42:10: note: subobject 'name' declared here 42 | uint8_t name[]; | ^~~~ cc1: all warnings being treated as errors make[5]: *** [CMakeFiles/umdns.dir/build.make:132: CMakeFiles/umdns.dir/service.c.o] Error 1 Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
-rw-r--r--service.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/service.c b/service.c
index 97b6f91..af3083e 100644
--- a/service.c
+++ b/service.c
@@ -218,6 +218,7 @@ service_load_blob(struct blob_attr *b)
uint8_t *d_txt;
int rem2;
int txt_len = 0;
+ unsigned int n;
blobmsg_parse(service_policy, ARRAY_SIZE(service_policy),
_tb, blobmsg_data(b), blobmsg_data_len(b));
@@ -228,8 +229,9 @@ service_load_blob(struct blob_attr *b)
blobmsg_for_each_attr(txt, _tb[SERVICE_TXT], rem2)
txt_len += 1 + strlen(blobmsg_get_string(txt));
+ n = strlen(blobmsg_name(b)) + 1;
s = calloc_a(sizeof(*s),
- &d_id, strlen(blobmsg_name(b)) + 1,
+ &d_id, n,
&d_instance, _tb[SERVICE_INSTANCE] ? strlen(blobmsg_get_string(_tb[SERVICE_INSTANCE])) + 1 : 0,
&d_service, strlen(blobmsg_get_string(_tb[SERVICE_SERVICE])) + 1,
&d_txt, txt_len);
@@ -237,7 +239,7 @@ service_load_blob(struct blob_attr *b)
return;
s->port = blobmsg_get_u32(_tb[SERVICE_PORT]);
- s->id = strcpy(d_id, blobmsg_name(b));
+ s->id = strncpy(d_id, blobmsg_name(b), n);
if (_tb[SERVICE_INSTANCE])
s->instance = strcpy(d_instance, blobmsg_get_string(_tb[SERVICE_INSTANCE]));
else