From: Richard Sandiford <richard.sandiford@arm.com>
To: Philipp Tomsich <philipp.tomsich@vrull.eu>
Cc: gcc-patches@gcc.gnu.org,
Tamar Christina <tamar.christina@arm.com>,
Christoph Muellner <christoph.muellner@vrull.eu>
Subject: Re: [PATCH] aarch64: fix off-by-one in reading cpuinfo
Date: Tue, 04 Oct 2022 10:10:25 +0100 [thread overview]
Message-ID: <mpt5yh0kl8e.fsf@arm.com> (raw)
In-Reply-To: <20221003212419.3337714-1-philipp.tomsich@vrull.eu> (Philipp Tomsich's message of "Mon, 3 Oct 2022 23:24:19 +0200")
Philipp Tomsich <philipp.tomsich@vrull.eu> writes:
> Fixes: 341573406b39
>
> Don't subtract one from the result of strnlen() when trying to point
> to the first character after the current string. This issue would
> cause individual characters (where the 128 byte buffers are stitched
> together) to be lost.
>
> gcc/ChangeLog:
>
> * config/aarch64/driver-aarch64.cc (readline): Fix off-by-one.
>
> Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
Thanks for the patch. Would it be possible to create a testcase along
the lines of gcc.target/aarch64/cpunative/native_cpu_15.c?
Richard
> ---
>
> gcc/config/aarch64/driver-aarch64.cc | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/config/aarch64/driver-aarch64.cc b/gcc/config/aarch64/driver-aarch64.cc
> index 52ff537908e..48250e68034 100644
> --- a/gcc/config/aarch64/driver-aarch64.cc
> +++ b/gcc/config/aarch64/driver-aarch64.cc
> @@ -203,9 +203,9 @@ readline (FILE *f)
> return std::string ();
> /* If we're not at the end of the line then override the
> \0 added by fgets. */
> - last = strnlen (buf, size) - 1;
> + last = strnlen (buf, size);
> }
> - while (!feof (f) && buf[last] != '\n');
> + while (!feof (f) && (last > 0 && buf[last - 1] != '\n'));
>
> std::string result (buf);
> free (buf);
prev parent reply other threads:[~2022-10-04 9:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-03 21:24 Philipp Tomsich
2022-10-04 9:10 ` Richard Sandiford [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=mpt5yh0kl8e.fsf@arm.com \
--to=richard.sandiford@arm.com \
--cc=christoph.muellner@vrull.eu \
--cc=gcc-patches@gcc.gnu.org \
--cc=philipp.tomsich@vrull.eu \
--cc=tamar.christina@arm.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).