[aarch64] Allocate space for err_str in aarch64_handle_attr_branch_protection
authorMatthew Malcomson <matthew.malcomson@arm.com>
Tue, 5 Nov 2019 15:35:15 +0000 (15:35 +0000)
committerMatthew Malcomson <matmal01@gcc.gnu.org>
Tue, 5 Nov 2019 15:35:15 +0000 (15:35 +0000)
-fsanitize=hwaddress found a one-byte overwrite when running the
testsuite here.  aarch64_handle_attr_branch_protection allocates
`strlen(str)` bytes for an error string, which is populated by
`strcpy(..., str)` in the case where the branch protection string is
completely invalid.

Not tested -- I don't want to re-build and it seems obvious.

gcc/ChangeLog:

2019-11-05  Matthew Malcomson  <matthew.malcomson@arm.com>

* config/aarch64/aarch64.c (aarch64_handle_attr_cpu): Allocate
enough bytes for the NULL character.

From-SVN: r277845

gcc/ChangeLog
gcc/config/aarch64/aarch64.c

index ca42d43f9eceb2a592ebb187270d3f99e7740b56..320b4923db953bc8c4953bfd4f7b7ca84430f211 100644 (file)
@@ -1,3 +1,8 @@
+2019-11-05  Matthew Malcomson  <matthew.malcomson@arm.com>
+
+       * config/aarch64/aarch64.c (aarch64_handle_attr_cpu): Allocate
+       enough bytes for the NULL character.
+
 2019-11-05  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/92280
index f28fe8047616a4db7fd40f33ff6b19b5c18078d0..1dfff331a5a2a1bc5eeba5a58e41f4bf2ad22468 100644 (file)
@@ -14156,7 +14156,7 @@ aarch64_handle_attr_cpu (const char *str)
  static bool
  aarch64_handle_attr_branch_protection (const char* str)
  {
-  char *err_str = (char *) xmalloc (strlen (str));
+  char *err_str = (char *) xmalloc (strlen (str) + 1);
   enum aarch64_parse_opt_result res = aarch64_parse_branch_protection (str,
                                                                      &err_str);
   bool success = false;