From 4b073774b23eb2c93c1d1601dd86899eb9852898 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 8 Dec 2020 19:21:03 +0100 Subject: [PATCH] argp: Don't pass invalid arguments to isspace() and isalnum(). * lib/argp-help.c (canon_doc_option): Cast character to 'unsigned int' before passing it to isspace() or isalnum(). --- ChangeLog | 6 ++++++ lib/argp-help.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index eaea8df7ca..3feedc1d33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2020-12-08 Bruno Haible + + argp: Don't pass invalid arguments to isspace() and isalnum(). + * lib/argp-help.c (canon_doc_option): Cast character to 'unsigned int' + before passing it to isspace() or isalnum(). + 2020-12-08 Bruno Haible argp: Don't rely on undefined behaviour of _tolower(). diff --git a/lib/argp-help.c b/lib/argp-help.c index 03fc6c79eb..acab00146f 100644 --- a/lib/argp-help.c +++ b/lib/argp-help.c @@ -720,12 +720,12 @@ canon_doc_option (const char **name) { int non_opt; /* Skip initial whitespace. */ - while (isspace (**name)) + while (isspace ((unsigned char) **name)) (*name)++; /* Decide whether this looks like an option (leading '-') or not. */ non_opt = (**name != '-'); /* Skip until part of name used for sorting. */ - while (**name && !isalnum (**name)) + while (**name && !isalnum ((unsigned char) **name)) (*name)++; return non_opt; } -- 2.39.5