[v2,2/4] examples/vm_power_manager: fix string truncation warning
diff mbox series

Message ID 20200821171017.50531-3-bruce.richardson@intel.com
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show
Series
  • fixes for example app builds
Related show

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Richardson, Bruce Aug. 21, 2020, 5:10 p.m. UTC
When compiling on ubuntu 20.04, a warning was issued about possible
truncation of the path string for the power management socket.

channel_manager.c: In function ‘add_all_channels’:
channel_manager.c:470:41: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 90 [-Wformat-truncation=]
  470 |     sizeof(chan_info->channel_path), "%s%s",
      |                                         ^~

This can be fixed by adding in an explicit truncation check to the code and
handling it appropriately.

Fixes: e8ae9b662506 ("examples/vm_power: channel manager and monitor in host")
Cc: stable@dpdk.org

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 examples/vm_power_manager/channel_manager.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

David Hunt Aug. 26, 2020, 10:09 a.m. UTC | #1
Hi Bruce,

On 21/8/2020 6:10 PM, Bruce Richardson wrote:
> When compiling on ubuntu 20.04, a warning was issued about possible
> truncation of the path string for the power management socket.
>
> channel_manager.c: In function ‘add_all_channels’:
> channel_manager.c:470:41: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 90 [-Wformat-truncation=]
>    470 |     sizeof(chan_info->channel_path), "%s%s",
>        |                                         ^~
>
> This can be fixed by adding in an explicit truncation check to the code and
> handling it appropriately.
>
> Fixes: e8ae9b662506 ("examples/vm_power: channel manager and monitor in host")
> Cc: stable@dpdk.org
>
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
>   examples/vm_power_manager/channel_manager.c | 10 ++++++++--
>   1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c
> index 3da01b46d8..0a28cb643b 100644
> --- a/examples/vm_power_manager/channel_manager.c
> +++ b/examples/vm_power_manager/channel_manager.c
> @@ -466,9 +466,15 @@ add_all_channels(const char *vm_name)
>   			continue;
>   		}
>   
> -		snprintf(chan_info->channel_path,
> +		if ((size_t)snprintf(chan_info->channel_path,
>   				sizeof(chan_info->channel_path), "%s%s",
> -				CHANNEL_MGR_SOCKET_PATH, dir->d_name);
> +				CHANNEL_MGR_SOCKET_PATH, dir->d_name)
> +					>= sizeof(chan_info->channel_path)) {
> +			RTE_LOG(ERR, CHANNEL_MANAGER, "Pathname too long for channel '%s%s'\n",
> +					CHANNEL_MGR_SOCKET_PATH, dir->d_name);
> +			rte_free(chan_info);
> +			continue;
> +		}
>   
>   		if (setup_channel_info(&vm_info, &chan_info, channel_num) < 0) {
>   			rte_free(chan_info);


Acked-by: David Hunt <david.hunt@intel.com>

Patch
diff mbox series

diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c
index 3da01b46d8..0a28cb643b 100644
--- a/examples/vm_power_manager/channel_manager.c
+++ b/examples/vm_power_manager/channel_manager.c
@@ -466,9 +466,15 @@  add_all_channels(const char *vm_name)
 			continue;
 		}
 
-		snprintf(chan_info->channel_path,
+		if ((size_t)snprintf(chan_info->channel_path,
 				sizeof(chan_info->channel_path), "%s%s",
-				CHANNEL_MGR_SOCKET_PATH, dir->d_name);
+				CHANNEL_MGR_SOCKET_PATH, dir->d_name)
+					>= sizeof(chan_info->channel_path)) {
+			RTE_LOG(ERR, CHANNEL_MANAGER, "Pathname too long for channel '%s%s'\n",
+					CHANNEL_MGR_SOCKET_PATH, dir->d_name);
+			rte_free(chan_info);
+			continue;
+		}
 
 		if (setup_channel_info(&vm_info, &chan_info, channel_num) < 0) {
 			rte_free(chan_info);