From 13157c1056407bc8c7d0d28772981bdd7cbc82c4 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Mon, 4 Feb 2019 23:49:49 +1030 Subject: [PATCH] [RS6000] Fix potiential buffer overflow * config/rs6000/rs6000.c (rs6000_indirect_call_template_1): Increase str[] size to 160, and comment. From-SVN: r268520 --- gcc/ChangeLog | 5 +++++ gcc/config/rs6000/rs6000.c | 41 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index efe3f5bfe6e..3c52283d93c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2019-02-04 Alan Modra + + * config/rs6000/rs6000.c (rs6000_indirect_call_template_1): Increase + str[] size to 160, and comment. + 2019-02-04 Alan Modra * config/rs6000/rs6000.c (rs6000_indirect_call_template_1), diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 7d417b626e8..711278c7422 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -21609,10 +21609,47 @@ rs6000_indirect_call_template_1 (rtx *operands, unsigned int funop, bool sibcall) { /* -Wformat-overflow workaround, without which gcc thinks that %u - might produce 10 digits. */ + might produce 10 digits. Note that -Wformat-overflow will not + currently warn here for str[], so do not rely on a warning to + ensure str[] is correctly sized. */ gcc_assert (funop <= MAX_RECOG_OPERANDS); - static char str[144]; /* 1 spare */ + /* Currently, funop is either 0 or 1. The maximum string is always + a !speculate 64-bit __tls_get_addr call. + + ABI_AIX: + . 9 ld 2,%3\n\t + . 27 .reloc .,R_PPC64_TLSGD,%2\n\t + . 29 .reloc .,R_PPC64_PLTSEQ,%z1\n\t + . 9 crset 2\n\t + . 27 .reloc .,R_PPC64_TLSGD,%2\n\t + . 30 .reloc .,R_PPC64_PLTCALL,%z1\n\t + . 10 beq%T1l-\n\t + . 10 ld 2,%4(1) + .--- + .151 + + ABI_ELFv2: + . 27 .reloc .,R_PPC64_TLSGD,%2\n\t + . 29 .reloc .,R_PPC64_PLTSEQ,%z1\n\t + . 9 crset 2\n\t + . 27 .reloc .,R_PPC64_TLSGD,%2\n\t + . 30 .reloc .,R_PPC64_PLTCALL,%z1\n\t + . 10 beq%T1l-\n\t + . 10 ld 2,%3(1) + .--- + .142 + + ABI_V4: + . 27 .reloc .,R_PPC64_TLSGD,%2\n\t + . 35 .reloc .,R_PPC64_PLTSEQ,%z1+32768\n\t + . 9 crset 2\n\t + . 27 .reloc .,R_PPC64_TLSGD,%2\n\t + . 36 .reloc .,R_PPC64_PLTCALL,%z1+32768\n\t + . 8 beq%T1l- + .--- + .141 */ + static char str[160]; /* 8 spare */ char *s = str; const char *ptrload = TARGET_64BIT ? "d" : "wz"; -- 2.30.2