On Tue, Apr 04, 2023 at 11:09:16AM -0700, Tyler Retzlaff wrote: > Use of ranges in designated initialization are a non-standard gcc > extension. > > Only initialize '_' and '/' elements of the array and filter tests > of characters through name with standard C isalnum before checking > the array. > > Suggested-by: Konstantin Ananyev <konstantin.anan...@huawei.com> > Suggested-by: Bruce Richardson <bruce.richard...@intel.com> > Signed-off-by: Tyler Retzlaff <roret...@linux.microsoft.com>
Acked-by: Bruce Richardson <bruce.richard...@intel.com> The array should probably be "static", which was a miss in the original version too. > --- > lib/telemetry/telemetry_data.c | 16 +++++++--------- > 1 file changed, 7 insertions(+), 9 deletions(-) > > diff --git a/lib/telemetry/telemetry_data.c b/lib/telemetry/telemetry_data.c > index 2bac2de..0dc091a 100644 > --- a/lib/telemetry/telemetry_data.c > +++ b/lib/telemetry/telemetry_data.c > @@ -2,6 +2,7 @@ > * Copyright(c) 2020 Intel Corporation > */ > > +#include <ctype.h> > #include <errno.h> > #include <stdlib.h> > #include <inttypes.h> > @@ -152,17 +153,14 @@ > static bool > valid_name(const char *name) > { > - char allowed[128] = { > - ['0' ... '9'] = 1, > - ['A' ... 'Z'] = 1, > - ['a' ... 'z'] = 1, > - ['_'] = 1, > - ['/'] = 1, > - }; > - while (*name != '\0') { > + /* non-alpha-numeric characters allowed in names */ > + const char allowed[128] = { ['_'] = 1, ['/'] = 1 }; > + > + for (; *name != '\0'; name++) { > + if (isalnum(*name)) > + continue; > if ((size_t)*name >= RTE_DIM(allowed) || allowed[(int)*name] == > 0) > return false; > - name++; > } > return true; > } > -- > 1.8.3.1 >