On Thu, Oct 22, 2026 at 08:54:11AM -0700, Stephen Hemminger wrote:
> On Thu, 22 Oct 2026 20:23:48 +0800
> Wei Chen <[email protected]> wrote:
> 
> > The _strip() function passes a char directly to isspace(), which is
> > undefined behavior. The ctype functions require an int argument that is
> > either an unsigned char value or EOF, but char is signed by default on
> > x86 and ARM, so any byte >= 0x80 in the input is promoted to a negative
> > int and indexes the ctype table out of bounds.
> > 
> > Such bytes are reachable from a user-provided config file containing
> > UTF-8 or other non-ASCII content.
> > 
> > Cast the argument to unsigned char, as is already done in
> > app/test-bbdev/test_bbdev_vector.c and elsewhere.
> > 
> > Fixes: eaafbad419bf ("cfgfile: library to interpret config files")
> > Cc: [email protected]
> > 
> > Signed-off-by: Wei Chen <[email protected]>
> > ---
> 
> Looks good, there seems to be lots of places with same issue.
> Perhaps putting helpers in rte_string_fns.h which handle the
> common ctype case and use comparisons to avoid pitfalls.
> 
>    static inline bool
>    rte_isspace(char c)
>    {
>       return c == ' ' || c == '\t' || c == '\n' ||
>              c == '\r' || c == '\f' || c == '\v';
>    }
> 
> Quick AI doodle.
> 
Not fully convinced we need a DPDK wrapper for this. If we do, I suggest
simplifying to just being a casting wrapper:

static inline bool
rte_isspace(char c) { return isspace((unsigned char)c); }

Rather than a wrapper, I'd prefer some sort of static check for this, if
such a thing is possible in checkpatches or similar. Better to teach how to
use the standard API properly than try and hide it. IMHO rte_ prefixed-
wrappers/replacements for standard functions should only be used in cases
where the standard function is missing on some platforms (e.g. strlcpy) or
has varying behaviour (basename).

/Bruce

Reply via email to