> From: Stephen Hemminger [mailto:step...@networkplumber.org] > Sent: Wednesday, 5 January 2022 19.02 > > The size argument to eal_set_runtime_dir is useless and was > being used incorrectly in strlcpy. It worked only because > all callers passed PATH_MAX which is same as sizeof the destination > runtime_dir. > > Signed-off-by: Stephen Hemminger <step...@networkplumber.org> > Suggested-by: Morten Brørup <m...@smartsharesystems.com> > --- > lib/eal/common/eal_common_config.c | 7 ++----- > lib/eal/common/eal_private.h | 4 +--- > lib/eal/freebsd/eal.c | 2 +- > lib/eal/linux/eal.c | 2 +- > 4 files changed, 5 insertions(+), 10 deletions(-) > > diff --git a/lib/eal/common/eal_common_config.c > b/lib/eal/common/eal_common_config.c > index 1c4c4dd585d0..62a9d7a198db 100644 > --- a/lib/eal/common/eal_common_config.c > +++ b/lib/eal/common/eal_common_config.c > @@ -29,12 +29,9 @@ rte_eal_get_runtime_dir(void) > } > > int > -eal_set_runtime_dir(char *run_dir, size_t size) > +eal_set_runtime_dir(const char *run_dir) > { > - size_t str_size; > - > - str_size = strlcpy(runtime_dir, run_dir, size); > - if (str_size >= size) { > + if (strlcpy(runtime_dir, run_dir, PATH_MAX) >= PATH_MAX) { > RTE_LOG(ERR, EAL, "Runtime directory string too long\n"); > return -1; > } > diff --git a/lib/eal/common/eal_private.h > b/lib/eal/common/eal_private.h > index 36bcc0b5a492..734f1f334b69 100644 > --- a/lib/eal/common/eal_private.h > +++ b/lib/eal/common/eal_private.h > @@ -681,13 +681,11 @@ eal_mem_set_dump(void *virt, size_t size, bool > dump); > * > * @param run_dir > * The new runtime directory path of DPDK > - * @param size > - * The size of the new runtime directory path in bytes. > * @return > * 0 on success, (-1) on failure. > */ > int > -eal_set_runtime_dir(char *run_dir, size_t size); > +eal_set_runtime_dir(const char *run_dir); > > /** > * Get the internal configuration structure. > diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c > index a1cd2462db1b..503e276dc27f 100644 > --- a/lib/eal/freebsd/eal.c > +++ b/lib/eal/freebsd/eal.c > @@ -123,7 +123,7 @@ eal_create_runtime_dir(void) > return -1; > } > > - if (eal_set_runtime_dir(run_dir, sizeof(run_dir))) > + if (eal_set_runtime_dir(run_dir)) > return -1; > > return 0; > diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c > index 80ffe1c7f9d8..a73ff75f65c9 100644 > --- a/lib/eal/linux/eal.c > +++ b/lib/eal/linux/eal.c > @@ -135,7 +135,7 @@ eal_create_runtime_dir(void) > return -1; > } > > - if (eal_set_runtime_dir(run_dir, sizeof(run_dir))) > + if (eal_set_runtime_dir(run_dir)) > return -1; > > return 0; > -- > 2.30.2 >
Reviewed-by: Morten Brørup<m...@smartsharesystems.com>