From: Arnaldo Carvalho de Melo <acme@redhat.com>
To: hyunji-Hong <onlygod0807@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Tools: lib: string: Fix isspace() parameter to avoid undefined behavior
Date: Fri, 19 Mar 2021 15:28:56 -0300 [thread overview]
Message-ID: <20210319182856.GA2120@redhat.com> (raw)
In-Reply-To: <20210319001415.8928-1-hyunji_hong@korea.ac.kr>
Em Fri, Mar 19, 2021 at 09:14:15AM +0900, hyunji-Hong escreveu:
> isspace() could be vulnerable in terms of unpredictable results. So, the parameter of the isspace() should be cast with 'unsigned int'. We found out that information through these sites. (Microsoft, Stack Overflow)
> url: [https://docs.microsoft.com/en-us/cpp/code-quality/c6328?view=msvc-160]
> url: [https://stackoverflow.com/questions/122721]
tools/ and the kernel versions of isspace are implemented in
include/linux/ctype.h and tools/include/linux/ctype.h.
- Arnaldo
> Signed-off-by: SeungHoon Woo, Hyunji Hong, Kyeongseok Yang <hyunji_hong@korea.ac.kr>
> ---
> tools/lib/string.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/lib/string.c b/tools/lib/string.c
> index 8b6892f959ab..7d01be5cdcf8 100644
> --- a/tools/lib/string.c
> +++ b/tools/lib/string.c
> @@ -123,7 +123,7 @@ size_t __weak strlcpy(char *dest, const char *src, size_t size)
> */
> char *skip_spaces(const char *str)
> {
> - while (isspace(*str))
> + while (isspace((unsigned char)*str))
> ++str;
> return (char *)str;
> }
> @@ -146,7 +146,7 @@ char *strim(char *s)
> return s;
>
> end = s + size - 1;
> - while (end >= s && isspace(*end))
> + while (end >= s && isspace((unsigned char)*end))
> end--;
> *(end + 1) = '\0';
>
> --
> 2.17.1
prev parent reply other threads:[~2021-03-19 18:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-19 0:14 [PATCH] Tools: lib: string: Fix isspace() parameter to avoid undefined behavior hyunji-Hong
2021-03-19 18:28 ` Arnaldo Carvalho de Melo [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210319182856.GA2120@redhat.com \
--to=acme@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=onlygod0807@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox