summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStijn Tintel2021-05-13 11:59:56 +0000
committerStijn Tintel2021-05-13 12:56:07 +0000
commitb777a0b53f7d89ab2a60e3eed7d98036806da9a4 (patch)
tree2b9da0dd21176da05a9c70a6fa5ebac7f01cc2e4
parent78aa36b0e9808e801c527c6dc47320e593309522 (diff)
downloadmdnsd-b777a0b53f7d89ab2a60e3eed7d98036806da9a4.tar.gz
service: fix compilation with GCC 10
Building with GCC 10.3.0 fails with the following error: service.c:243:10: error: 'strncpy' 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] 243 | s->id = strncpy(d_id, blobmsg_name(b), n); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Fix it by passing the length returned by strlen to strncpy without adding an extra byte for the string terminator. Add the extra byte only in the calloc_a call, which will initialize it to NULL. Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be> Acked-by: Hauke Mehrtens <hauke@hauke-m.de> Acked-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
-rw-r--r--service.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/service.c b/service.c
index 66a3382..bd9f985 100644
--- a/service.c
+++ b/service.c
@@ -230,9 +230,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;
+ n = strlen(blobmsg_name(b));
s = calloc_a(sizeof(*s),
- &d_id, n,
+ &d_id, n + 1,
&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);