examples/vm_power: fix format-truncation warning
PATCH 1/1 examples/vm_power: fix format-truncation warning
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.
--- examples/vm_power_manager/channel_manager.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
examples/vm_power_manager/channel_manager.c +10 -2
@@ -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 ) {
Signature · 1 line
2.53.0
Quoted 12 lines · On Wed, 25 Feb 2026 17:36:32 +0000 Kevin Traynor <[email protected]> wrote:
Without libbsd-devel strlcpy is defined as
rte_strlcpyand 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); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 6 lines
Check for truncation of socket_path[4096] into channel_path[108] to remove warning.
Signed-off-by Kevin Traynor <[email protected]>
Since socket_path is a unix domain socket path. It should be UNIX_PATH_MAX (108) not PATH_MAX (4096)
Quoted 18 lines · Stephen Hemminger
Quoted 15 lines · On Wed, 25 Feb 2026 17:36:32 +0000 Kevin Traynor <[email protected]> wrote:
Without libbsd-devel strlcpy is defined as
rte_strlcpyand 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.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Kevin Traynor <[email protected]>Since
socket_pathis a unix domain socket path. It should beUNIX_PATH_MAX(108) notPATH_MAX(4096)
Yeah, I had adjusted all the socket_path/names in the file to UNIX_PATH_MAX as an initial fix but it spewed a different truncation warning as one of them gets a copy from dirent->d_name which is 256.
So considering it's just an optimization of example code and hasn't really been developed over the last few years, I just fixed the warning that showed up.
Thomas Monjalon
Applied26/02/2026 11:48, Kevin Traynor:
Quoted 27 lines · Stephen Hemminger
Quoted 18 lines
Quoted 15 lines · On Wed, 25 Feb 2026 17:36:32 +0000 Kevin Traynor <[email protected]> wrote:
Without libbsd-devel strlcpy is defined as
rte_strlcpyand 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.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Kevin Traynor <[email protected]>Since
socket_pathis a unix domain socket path. It should beUNIX_PATH_MAX(108) notPATH_MAX(4096)
Quoted 7 lines
Yeah, I had adjusted all the socket_path/names in the file to
UNIX_PATH_MAXas an initial fix but it spewed a different truncation warning as one of them gets a copy fromdirent->d_namewhich is 256.So considering it's just an optimization of example code and hasn't really been developed over the last few years, I just fixed the warning that showed up.
Yes I suspect this example to have many other problems. The whole example should be reconsidered.
Applied, thanks.
Thomas Monjalon
Applied25/02/2026 18:36, Kevin Traynor:
Quoted 12 lines
Without libbsd-devel strlcpy is defined as
rte_strlcpyand 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); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 6 lines
Check for truncation of socket_path[4096] into channel_path[108] to remove warning.
Signed-off-by Kevin Traynor <[email protected]>
Applied, thanks.