mbox series

[0/7] media: string truncate warnings: fix low-hanging fruit

Message ID 20230922105036.3148784-1-hverkuil-cisco@xs4all.nl
Headers show
Series media: string truncate warnings: fix low-hanging fruit | expand

Message

Hans Verkuil Sept. 22, 2023, 10:50 a.m. UTC
While going through the string truncate warnings I found several that
were easy to fix.

The remainder of the warnings (about 33) are all of this type:

	char name1[32];
	char name2[32];

	snprintf(name2, sizeof(name2), "foo:%s", name1);

Since the [32] part of the character arrays is related to uAPI structures,
this is not so easy to fix.

One option might be to create a helper function to do the concatenation
and that warns (once) if actual truncation takes place. Since in most
case the strings are short enough.

Even if we increase the size to e.g. 64 in the uAPI to avoid some of the
current truncates, that will still cause the same warning, so a helper
function that is smarter would probably still be needed.

Comments/ideas are welcome.

Regards,

	Hans

Hans Verkuil (7):
  media: allegro-dvt: increase buffer size in msg_type_name()
  media: cadence: increase buffer size in csi2tx_get_resources()
  media: atomisp: ia_ccs_debug.c: increase enable_info buffer
  media: vivid: avoid integer overflow
  media: ipu-bridge: increase sensor_name size
  media: cx18: increase in_workq_name size
  media: rc: ati_remote: increase mouse_name buffer size

 drivers/media/pci/cx18/cx18-driver.h                            | 2 +-
 drivers/media/platform/allegro-dvt/allegro-mail.c               | 2 +-
 drivers/media/platform/cadence/cdns-csi2tx.c                    | 2 +-
 drivers/media/rc/ati_remote.c                                   | 2 +-
 drivers/media/test-drivers/vivid/vivid-rds-gen.c                | 2 +-
 .../staging/media/atomisp/pci/runtime/debug/src/ia_css_debug.c  | 2 +-
 include/media/ipu-bridge.h                                      | 2 +-
 7 files changed, 7 insertions(+), 7 deletions(-)

Comments

Sean Young Sept. 22, 2023, 10:59 a.m. UTC | #1
On Fri, Sep 22, 2023 at 12:50:36PM +0200, Hans Verkuil wrote:
> Fixes this compiler warning:
> 
> drivers/media/rc/ati_remote.c: In function 'ati_remote_probe':
> drivers/media/rc/ati_remote.c:876:21: warning: ' mouse' directive output may be truncated writing 6 bytes into a region of size between 1 and 80 [-Wformat-truncation=]
>   876 |                  "%s mouse", ati_remote->rc_name);
>       |                     ^~~~~~
> drivers/media/rc/ati_remote.c:875:9: note: 'snprintf' output between 7 and 86 bytes into a destination of size 80
>   875 |         snprintf(ati_remote->mouse_name, sizeof(ati_remote->mouse_name),
>       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   876 |                  "%s mouse", ati_remote->rc_name);
>       |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> Cc: Sean Young <sean@mess.org>

I was looking at this problem this morning - you beat me to it. :)

Reviewed-by: Sean Young <sean@mess.org>

Thanks
Sean

> ---
>  drivers/media/rc/ati_remote.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/rc/ati_remote.c b/drivers/media/rc/ati_remote.c
> index fff4dd48eaca..d7721e60776e 100644
> --- a/drivers/media/rc/ati_remote.c
> +++ b/drivers/media/rc/ati_remote.c
> @@ -251,7 +251,7 @@ struct ati_remote {
>  
>  	char rc_name[NAME_BUFSIZE];
>  	char rc_phys[NAME_BUFSIZE];
> -	char mouse_name[NAME_BUFSIZE];
> +	char mouse_name[NAME_BUFSIZE + 6];
>  	char mouse_phys[NAME_BUFSIZE];
>  
>  	wait_queue_head_t wait;
> -- 
> 2.40.1
Hans de Goede Sept. 22, 2023, 1:19 p.m. UTC | #2
Hi,

On 9/22/23 12:50, Hans Verkuil wrote:
> Fixes these compiler warnings:
> 
> drivers/staging/media/atomisp/pci/runtime/debug/src/ia_css_debug.c: In function 'ia_css_debug_pipe_graph_dump_stage':
> drivers/staging/media/atomisp/pci/runtime/debug/src/ia_css_debug.c:2786:66: warning: '\n' directive output may be truncated writing 2 bytes into a region of size between 0 and 198 [-Wformat-truncation=]
>  2786 |                                                          "%s\\n%s\\n%s",
>       |                                                                  ^~~
> drivers/staging/media/atomisp/pci/runtime/debug/src/ia_css_debug.c:2785:49: note: 'snprintf' output between 5 and 302 bytes into a destination of size 200
>  2785 |                                                 snprintf(enable_info, sizeof(enable_info),
>       |                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>  2786 |                                                          "%s\\n%s\\n%s",
>       |                                                          ~~~~~~~~~~~~~~~
>  2787 |                                                          enable_info1, enable_info2,
>       |                                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~
>  2788 |                                                          enable_info3);
>       |                                                          ~~~~~~~~~~~~~
> drivers/staging/media/atomisp/pci/runtime/debug/src/ia_css_debug.c:2772:66: warning: '\n' directive output may be truncated writing 2 bytes into a region of size between 0 and 198 [-Wformat-truncation=]
>  2772 |                                                          "%s\\n%s\\n%s",
>       |                                                                  ^~~
> drivers/staging/media/atomisp/pci/runtime/debug/src/ia_css_debug.c:2771:49: note: 'snprintf' output between 5 and 302 bytes into a destination of size 200
>  2771 |                                                 snprintf(enable_info, sizeof(enable_info),
>       |                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>  2772 |                                                          "%s\\n%s\\n%s",
>       |                                                          ~~~~~~~~~~~~~~~
>  2773 |                                                          enable_info1, enable_info2,
>       |                                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~
>  2774 |                                                          enable_info3);
>       |                                                          ~~~~~~~~~~~~~
> drivers/staging/media/atomisp/pci/runtime/debug/src/ia_css_debug.c:2749:92: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]
>  2749 |                                         snprintf(enable_info, sizeof(enable_info), "%s\\n%s",
>       |                                                                                            ^
> drivers/staging/media/atomisp/pci/runtime/debug/src/ia_css_debug.c:2749:41: note: 'snprintf' output between 3 and 201 bytes into a destination of size 200
>  2749 |                                         snprintf(enable_info, sizeof(enable_info), "%s\\n%s",
>       |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>  2750 |                                                  enable_info1, enable_info2);
>       |                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> Cc: Hans de Goede <hdegoede@redhat.com>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans





> ---
>  .../staging/media/atomisp/pci/runtime/debug/src/ia_css_debug.c  | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/media/atomisp/pci/runtime/debug/src/ia_css_debug.c b/drivers/staging/media/atomisp/pci/runtime/debug/src/ia_css_debug.c
> index bb6204cb42c5..8b0251073f93 100644
> --- a/drivers/staging/media/atomisp/pci/runtime/debug/src/ia_css_debug.c
> +++ b/drivers/staging/media/atomisp/pci/runtime/debug/src/ia_css_debug.c
> @@ -2673,7 +2673,7 @@ ia_css_debug_pipe_graph_dump_stage(
>  		char enable_info1[100];
>  		char enable_info2[100];
>  		char enable_info3[100];
> -		char enable_info[200];
> +		char enable_info[302];
>  		struct ia_css_binary_info *bi = stage->binary_info;
>  
>  		/* Split it in 2 function-calls to keep the amount of