Without libbsd-devel strlcpy is defined as rte_strlcpy and a warning is
raised for format-truncation. Observed with gcc 15.2.1.

In function ‘rte_strlcpy’,
    inlined from ‘add_host_channels’ at
../examples/vm_power_manager/channel_manager.c:600:3:
../lib/eal/include/rte_string_fns.h:63:24:
warning: ‘%s’ directive output may be truncated writing up to
4095 bytes into a region of size 108 [-Wformat-truncation=]
63 |         return (size_t)snprintf(dst, size, "%s", src);
   |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check for truncation of socket_path[4096] into channel_path[108] to
remove warning.

Cc: [email protected]

Signed-off-by: Kevin Traynor <[email protected]>
---
 examples/vm_power_manager/channel_manager.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/examples/vm_power_manager/channel_manager.c 
b/examples/vm_power_manager/channel_manager.c
index 7d7efdd05a..b69449c61d 100644
--- a/examples/vm_power_manager/channel_manager.c
+++ b/examples/vm_power_manager/channel_manager.c
@@ -561,4 +561,5 @@ add_host_channels(void)
        struct core_info *ci;
        struct channel_info *chan_infos[RTE_MAX_LCORE];
+       size_t channel_path_size;
        int i;
 
@@ -598,6 +599,13 @@ add_host_channels(void)
                }
                chan_infos[i] = chan_info;
-               strlcpy(chan_info->channel_path, socket_path,
-                               sizeof(chan_info->channel_path));
+               channel_path_size = sizeof(chan_info->channel_path);
+               if (strlcpy(chan_info->channel_path, socket_path,
+                             channel_path_size) >= channel_path_size) {
+                       RTE_LOG(ERR, CHANNEL_MANAGER, "Socket path is too long "
+                               "'%s' >= %zu\n", socket_path, 
channel_path_size);
+                       rte_free(chan_info);
+                       chan_infos[i] = NULL;
+                       goto error;
+               }
 
                if (setup_host_channel_info(&chan_info, i) < 0) {
-- 
2.53.0

Reply via email to