diff mbox series

umdns: fix compilation with GCC 10

Message ID 20200830220703.218411-1-rosenp@gmail.com
State Rejected
Delegated to: Petr Štetiar
Headers show
Series umdns: fix compilation with GCC 10 | expand

Commit Message

Rosen Penev Aug. 30, 2020, 10:07 p.m. UTC
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(-)

Comments

Petr Štetiar Aug. 31, 2020, 7:08 a.m. UTC | #1
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
Rosen Penev Aug. 31, 2020, 7:53 a.m. UTC | #2
> 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
Petr Štetiar Aug. 31, 2020, 8:29 a.m. UTC | #3
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
Rosen Penev Aug. 31, 2020, 9:06 a.m. UTC | #4
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
Petr Štetiar Aug. 31, 2020, 9:35 a.m. UTC | #5
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
Hauke Mehrtens Aug. 31, 2020, 4:41 p.m. UTC | #6
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
Rosen Penev Aug. 31, 2020, 8:51 p.m. UTC | #7
> 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
>
diff mbox series

Patch

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