Message ID | 20200830220703.218411-1-rosenp@gmail.com |
---|---|
State | Rejected |
Delegated to: | Petr Štetiar |
Headers | show |
Series | umdns: fix compilation with GCC 10 | expand |
Rosen Penev <rosenp@gmail.com> [2020-08-30 15:07:03]: Hi, > /service.c:242: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] > 242 | s->id = strncpy(d_id, blobmsg_name(b), n); how could one reproduce this error message? > Signed-off-by: Rosen Penev <rosenp@gmail.com> > --- > service.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/service.c b/service.c > index 53f44c1..e649b64 100644 > --- a/service.c > +++ b/service.c > @@ -240,7 +240,7 @@ service_load_blob(struct blob_attr *b) > return; > > s->port = blobmsg_get_u32(_tb[SERVICE_PORT]); > - s->id = strncpy(d_id, blobmsg_name(b), n); > + s->id = memcpy(d_id, blobmsg_name(b), n); -- ynezz
> On Aug 31, 2020, at 00:08, Petr Štetiar <ynezz@true.cz> wrote: > > Rosen Penev <rosenp@gmail.com> [2020-08-30 15:07:03]: > > Hi, > >> /service.c:242: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] >> 242 | s->id = strncpy(d_id, blobmsg_name(b), n); > > how could one reproduce this error message? GCC10? > >> Signed-off-by: Rosen Penev <rosenp@gmail.com> >> --- >> service.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/service.c b/service.c >> index 53f44c1..e649b64 100644 >> --- a/service.c >> +++ b/service.c >> @@ -240,7 +240,7 @@ service_load_blob(struct blob_attr *b) >> return; >> >> s->port = blobmsg_get_u32(_tb[SERVICE_PORT]); >> - s->id = strncpy(d_id, blobmsg_name(b), n); >> + s->id = memcpy(d_id, blobmsg_name(b), n); > > -- ynezz
Rosen Penev <rosenp@gmail.com> [2020-08-31 00:53:32]: > >> /service.c:242: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] > >> 242 | s->id = strncpy(d_id, blobmsg_name(b), n); > > > > how could one reproduce this error message? > GCC10? I've `gcc-10 (Ubuntu 10.1.0-2ubuntu1~18.04) 10.1.0` and I'm afraid, thats not enough. I've tried to compile it with following: /usr/bin/gcc-10 -D_FORTIFY_SOURCE=2 -I/opt/devel/openwrt/testing/include -g -Os -ggdb -Wextra -Wall -Werror --std=gnu99 -Wmissing-declarations -Wno-unused-parameter -fstack-protector-strong -Wformat -Werror=format-security -o CMakeFiles/umdns.dir/service.c.o -c /opt/devel/openwrt/c-projects/mdnsd/service.c which "just" yields following errors in service.c: service.c:110:10: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Werror=sign-compare] service.c:279:16: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare] -- ynezz
Sent from my iPhone > On Aug 31, 2020, at 01:29, Petr Štetiar <ynezz@true.cz> wrote: > > Rosen Penev <rosenp@gmail.com> [2020-08-31 00:53:32]: > >>>> /service.c:242: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] >>>> 242 | s->id = strncpy(d_id, blobmsg_name(b), n); >>> >>> how could one reproduce this error message? >> GCC10? > > I've `gcc-10 (Ubuntu 10.1.0-2ubuntu1~18.04) 10.1.0` and I'm afraid, thats not > enough. I've tried to compile it with following: > > /usr/bin/gcc-10 -D_FORTIFY_SOURCE=2 -I/opt/devel/openwrt/testing/include -g -Os > -ggdb -Wextra -Wall -Werror --std=gnu99 -Wmissing-declarations > -Wno-unused-parameter -fstack-protector-strong -Wformat -Werror=format-security > -o CMakeFiles/umdns.dir/service.c.o -c /opt/devel/openwrt/c-projects/mdnsd/service.c > > which "just" yields following errors in service.c: > > service.c:110:10: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Werror=sign-compare] > service.c:279:16: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare] I compile with target GCC 10, not host. > > -- ynezz
Rosen Penev <rosenp@gmail.com> [2020-08-31 02:06:50]:
> I compile with target GCC 10, not host.
Then as you can see its probably some issue with GCC 10 for that target (which
one is that?) or something like that, because I'm not able to trigger that
with my GCC 10. Your proposed fix seems not correct as well, as blob_name is
`const char*`, so I don't see a point of replacing strncpy with memcpy just to
silence (most likely) bogus compiler error. If it's not false positive, then
it needs to be fixed properly, not silenced by memcpy usage.
-- ynezz
On 8/31/20 11:35 AM, Petr Štetiar wrote: > Rosen Penev <rosenp@gmail.com> [2020-08-31 02:06:50]: > >> I compile with target GCC 10, not host. > > Then as you can see its probably some issue with GCC 10 for that target (which > one is that?) or something like that, because I'm not able to trigger that > with my GCC 10. Your proposed fix seems not correct as well, as blob_name is > `const char*`, so I don't see a point of replacing strncpy with memcpy just to > silence (most likely) bogus compiler error. If it's not false positive, then > it needs to be fixed properly, not silenced by memcpy usage. > > -- ynezz Hi, I am seeing the same error when compiling for the lantiq target (big endian MIPS) with GCC 10.2.0 on current master. Kevin already did a change in this part of the code to fix a compile problem with GCC 10 on x86_64: https://git.openwrt.org/?p=project/mdnsd.git;a=commitdiff;h=eadfa26a5cf31e27f551c37c1362983e9db37c4d This commit is in master. Hauke
> On Aug 31, 2020, at 9:41 AM, Hauke Mehrtens <hauke@hauke-m.de> wrote: > > On 8/31/20 11:35 AM, Petr Štetiar wrote: >> Rosen Penev <rosenp@gmail.com> [2020-08-31 02:06:50]: >> >>> I compile with target GCC 10, not host. >> >> Then as you can see its probably some issue with GCC 10 for that target (which >> one is that?) or something like that, because I'm not able to trigger that >> with my GCC 10. Your proposed fix seems not correct as well, as blob_name is >> `const char*`, so I don't see a point of replacing strncpy with memcpy just to >> silence (most likely) bogus compiler error. If it's not false positive, then >> it needs to be fixed properly, not silenced by memcpy usage. >> >> -- ynezz > > Hi, > > I am seeing the same error when compiling for the lantiq target (big > endian MIPS) with GCC 10.2.0 on current master. > > Kevin already did a change in this part of the code to fix a compile > problem with GCC 10 on x86_64: > https://git.openwrt.org/?p=project/mdnsd.git;a=commitdiff;h=eadfa26a5cf31e27f551c37c1362983e9db37c4d > This commit is in master. Yes. But it fails on mips and mvebu. > > Hauke >
On 8/31/20 10:51 PM, Rosen Penev wrote: > > >> On Aug 31, 2020, at 9:41 AM, Hauke Mehrtens <hauke@hauke-m.de> wrote: >> >> On 8/31/20 11:35 AM, Petr Štetiar wrote: >>> Rosen Penev <rosenp@gmail.com> [2020-08-31 02:06:50]: >>> >>>> I compile with target GCC 10, not host. >>> >>> Then as you can see its probably some issue with GCC 10 for that target (which >>> one is that?) or something like that, because I'm not able to trigger that >>> with my GCC 10. Your proposed fix seems not correct as well, as blob_name is >>> `const char*`, so I don't see a point of replacing strncpy with memcpy just to >>> silence (most likely) bogus compiler error. If it's not false positive, then >>> it needs to be fixed properly, not silenced by memcpy usage. >>> >>> -- ynezz >> >> Hi, >> >> I am seeing the same error when compiling for the lantiq target (big >> endian MIPS) with GCC 10.2.0 on current master. >> >> Kevin already did a change in this part of the code to fix a compile >> problem with GCC 10 on x86_64: >> https://git.openwrt.org/?p=project/mdnsd.git;a=commitdiff;h=eadfa26a5cf31e27f551c37c1362983e9db37c4d >> This commit is in master. > Yes. But it fails on mips and mvebu. I see this problem also on MIPS malte 32 BE, but not on Armvirt 64. It looks like this only happens on 32 bit targets. I also tried the recent GCC 10.3.0-RC-20210401 and it shows the same problem. For me this also looks like a compiler error, but we probably need a workaround for it. Hauke
diff --git a/service.c b/service.c index 53f44c1..e649b64 100644 --- a/service.c +++ b/service.c @@ -240,7 +240,7 @@ service_load_blob(struct blob_attr *b) return; s->port = blobmsg_get_u32(_tb[SERVICE_PORT]); - s->id = strncpy(d_id, blobmsg_name(b), n); + s->id = memcpy(d_id, blobmsg_name(b), n); if (_tb[SERVICE_INSTANCE]) s->instance = strcpy(d_instance, blobmsg_get_string(_tb[SERVICE_INSTANCE])); else
The previous fix seems to not be enough. /service.c:242: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] 242 | s->id = strncpy(d_id, blobmsg_name(b), n); Signed-off-by: Rosen Penev <rosenp@gmail.com> --- service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)