public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] aarch64: fix off-by-one in reading cpuinfo
@ 2022-10-03 21:24 Philipp Tomsich
  2022-10-04  9:10 ` Richard Sandiford
  0 siblings, 1 reply; 2+ messages in thread
From: Philipp Tomsich @ 2022-10-03 21:24 UTC (permalink / raw)
  To: gcc-patches
  Cc: Richard Sandiford, Tamar Christina, Christoph Muellner, Philipp Tomsich

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>

---

 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);
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] aarch64: fix off-by-one in reading cpuinfo
  2022-10-03 21:24 [PATCH] aarch64: fix off-by-one in reading cpuinfo Philipp Tomsich
@ 2022-10-04  9:10 ` Richard Sandiford
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Sandiford @ 2022-10-04  9:10 UTC (permalink / raw)
  To: Philipp Tomsich; +Cc: gcc-patches, Tamar Christina, Christoph Muellner

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);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-04  9:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-03 21:24 [PATCH] aarch64: fix off-by-one in reading cpuinfo Philipp Tomsich
2022-10-04  9:10 ` Richard Sandiford

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).