aboutsummaryrefslogtreecommitdiff
path: root/gas/config/tc-tic54x.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2019-05-10 16:57:31 +0100
committerNick Clifton <nickc@redhat.com>2019-05-14 10:42:25 +0100
commit3076e59490428c9719765f9b007d6d0d0238f006 (patch)
treecf5af362a3a1e16f2df44961241dc9b4d1cab77f /gas/config/tc-tic54x.c
parenta6d0f2490c0c7969eb60038f01c0ee0f46e4d5fd (diff)
downloadgdb-3076e59490428c9719765f9b007d6d0d0238f006.zip
gdb-3076e59490428c9719765f9b007d6d0d0238f006.tar.gz
gdb-3076e59490428c9719765f9b007d6d0d0238f006.tar.bz2
A series of fixes to addres problems detected by compiling the assembler with address sanitization enabled.
PR 24538 gas * macro.c (get_any_string): Increase size of buffer used to hold decimal value of expression result. * dw2gencfi.c (get_debugseg_name): Handle an empty name. * dwarf2dbg.c (get_filenum): Catch integer wraparound when extending allocate file array. (dwarf2_directive_filename): Add extra checks of the computed file number. * config/tc-arm.c (arm_tc_equal_in_insn): Insert copy of name into warning hash table. (s_arm_eabi_attribute): Check for obj_elf_vendor_attribute returning -1. * config/tc-i386.c (i386_output_nops): Catch an attempt to generate nops of negative lengths. * as.h (MAX_LITTLENUMS): Move definition to here from... * config/atof-ieee.c: ...here. * config/tc-aarch64.c: ...here. * config/tc-arc.c: ...here. * config/tc-arm.c: ...here. * config/tc-epiphany.c: ...here. * config/tc-i386.c: ...here. * config/tc-ia64.c: ...here. (And correct the value). * config/tc-m32c.c: ...here. * config/tc-m32r.c: ...here. * config/tc-metag.c: ...here. * config/tc-microblaze.c: ...here. * config/tc-nds32.c: ...here. * config/tc-or1k.c: ...here. * config/tc-score.c: ...here. * config/tc-score7.c: ...here. * config/tc-tic4x.c: ...here. * config/tc-tilegx.c: ...here. * config/tc-tilepro.c: ...here. * config/tc-visium.c: ...here. * config/tc-sh.c (md_assemble): Add check for an instruction with no opcodes. * config/tc-mips.c (mips_lookup_insn): Add check for very short instruction name. * config/tc-tic54x.c: Use unsigned chars to access is_end_of_line array. (tic54x_start_line_hook): Check for an empty line. (next_line_shows_parallel): Do not walk off the end of the string. (tic54x_macro_start): Check for too much macro nesting. (tic54x_start_label): Add label_start parameter. Use this parameter to check the first character of the label. * config/tc-tic54x.h (TC_START_LABEL_WITHOUT_COLON): Pass line_start variable to tic54x_start_label. PR 24538 opcodes * ia64-opc.c (ia64_find_matching_opcode): Check for reaching the end of the table prematurely.
Diffstat (limited to 'gas/config/tc-tic54x.c')
-rw-r--r--gas/config/tc-tic54x.c68
1 files changed, 36 insertions, 32 deletions
diff --git a/gas/config/tc-tic54x.c b/gas/config/tc-tic54x.c
index dc217ad..6e2b05d 100644
--- a/gas/config/tc-tic54x.c
+++ b/gas/config/tc-tic54x.c
@@ -185,7 +185,8 @@ static struct hash_control *subsym_recurse_hash; /* Prevent infinite recurse. *
static struct hash_control *math_hash; /* Built-in math functions. */
/* Allow maximum levels of macro nesting; level 0 is the main substitution
symbol table. The other assembler only does 32 levels, so there! */
-static struct hash_control *subsym_hash[100];
+#define MAX_SUBSYM_HASH 100
+static struct hash_control *subsym_hash[MAX_SUBSYM_HASH];
/* Keep track of local labels so we can substitute them before GAS sees them
since macros use their own 'namespace' for local labels, use a separate hash
@@ -336,7 +337,7 @@ tic54x_asg (int x ATTRIBUTE_UNUSED)
str = input_line_pointer;
while ((c = *input_line_pointer) != ',')
{
- if (is_end_of_line[(int) *input_line_pointer])
+ if (is_end_of_line[(unsigned char) c])
break;
++input_line_pointer;
}
@@ -645,7 +646,7 @@ tic54x_struct (int arg)
{
/* Offset is ignored in inner structs. */
SKIP_WHITESPACE ();
- if (!is_end_of_line[(int) *input_line_pointer])
+ if (!is_end_of_line[(unsigned char) *input_line_pointer])
start_offset = get_absolute_expression ();
else
start_offset = 0;
@@ -835,7 +836,7 @@ tic54x_struct_field (int type)
int longword_align = 0;
SKIP_WHITESPACE ();
- if (!is_end_of_line[(int) *input_line_pointer])
+ if (!is_end_of_line[(unsigned char) *input_line_pointer])
count = get_absolute_expression ();
switch (type)
@@ -1105,7 +1106,7 @@ tic54x_global (int type)
if (c == ',')
{
input_line_pointer++;
- if (is_end_of_line[(int) *input_line_pointer])
+ if (is_end_of_line[(unsigned char) *input_line_pointer])
c = *input_line_pointer;
}
}
@@ -1487,7 +1488,7 @@ tic54x_version (int x ATTRIBUTE_UNUSED)
SKIP_WHITESPACE ();
ver = input_line_pointer;
- while (!is_end_of_line[(int) *input_line_pointer])
+ while (!is_end_of_line[(unsigned char) *input_line_pointer])
++input_line_pointer;
c = *input_line_pointer;
*input_line_pointer = 0;
@@ -1645,7 +1646,7 @@ tic54x_align_words (int arg)
/* Only ".align" with no argument is allowed within .struct/.union. */
int count = arg;
- if (!is_end_of_line[(int) *input_line_pointer])
+ if (!is_end_of_line[(unsigned char) *input_line_pointer])
{
if (arg == 2)
as_warn (_("Argument to .even ignored"));
@@ -1913,7 +1914,7 @@ tic54x_include (int ignored ATTRIBUTE_UNUSED)
else
{
filename = input_line_pointer;
- while (!is_end_of_line[(int) *input_line_pointer])
+ while (!is_end_of_line[(unsigned char) *input_line_pointer])
++input_line_pointer;
c = *input_line_pointer;
*input_line_pointer = '\0';
@@ -1949,7 +1950,7 @@ tic54x_message (int type)
else
{
msg = input_line_pointer;
- while (!is_end_of_line[(int) *input_line_pointer])
+ while (!is_end_of_line[(unsigned char) *input_line_pointer])
++input_line_pointer;
c = *input_line_pointer;
*input_line_pointer = 0;
@@ -2027,7 +2028,7 @@ tic54x_loop (int count)
ILLEGAL_WITHIN_STRUCT ();
SKIP_WHITESPACE ();
- if (!is_end_of_line[(int) *input_line_pointer])
+ if (!is_end_of_line[(unsigned char) *input_line_pointer])
count = get_absolute_expression ();
do_repeat ((size_t) count, "LOOP", "ENDLOOP");
@@ -2052,7 +2053,7 @@ tic54x_break (int ignore ATTRIBUTE_UNUSED)
ILLEGAL_WITHIN_STRUCT ();
SKIP_WHITESPACE ();
- if (!is_end_of_line[(int) *input_line_pointer])
+ if (!is_end_of_line[(unsigned char) *input_line_pointer])
cond = get_absolute_expression ();
if (cond)
@@ -2140,7 +2141,7 @@ tic54x_sblock (int ignore ATTRIBUTE_UNUSED)
seg->flags |= SEC_TIC54X_BLOCK;
c = *input_line_pointer;
- if (!is_end_of_line[(int) c])
+ if (!is_end_of_line[(unsigned char) c])
++input_line_pointer;
}
@@ -2239,7 +2240,7 @@ tic54x_var (int ignore ATTRIBUTE_UNUSED)
if (c == ',')
{
++input_line_pointer;
- if (is_end_of_line[(int) *input_line_pointer])
+ if (is_end_of_line[(unsigned char) *input_line_pointer])
c = *input_line_pointer;
}
}
@@ -2275,7 +2276,7 @@ tic54x_mlib (int ignore ATTRIBUTE_UNUSED)
{
SKIP_WHITESPACE ();
len = 0;
- while (!is_end_of_line[(int) *input_line_pointer]
+ while (!is_end_of_line[(unsigned char) *input_line_pointer]
&& !ISSPACE (*input_line_pointer))
{
obstack_1grow (&notes, *input_line_pointer);
@@ -2497,7 +2498,11 @@ md_parse_option (int c, const char *arg)
void
tic54x_macro_start (void)
{
- ++macro_level;
+ if (++macro_level >= MAX_SUBSYM_HASH)
+ {
+ as_fatal (_("Macro nesting is too deep"));
+ return;
+ }
subsym_hash[macro_level] = hash_new ();
local_label_hash[macro_level] = hash_new ();
}
@@ -3081,7 +3086,7 @@ get_operands (struct opstruct operands[], char *line)
int expecting_operand = 0;
int i;
- while (numexp < MAX_OPERANDS && !is_end_of_line[(int) *lptr])
+ while (numexp < MAX_OPERANDS && !is_end_of_line[(unsigned char) *lptr])
{
int paren_not_balanced = 0;
char *op_start, *op_end;
@@ -3143,7 +3148,7 @@ get_operands (struct opstruct operands[], char *line)
while (*lptr && ISSPACE (*lptr++))
;
- if (!is_end_of_line[(int) *lptr])
+ if (!is_end_of_line[(unsigned char) *lptr])
{
as_bad (_("Extra junk on line"));
return -1;
@@ -4195,7 +4200,7 @@ static int
next_line_shows_parallel (char *next_line)
{
/* Look for the second half. */
- while (ISSPACE (*next_line))
+ while (*next_line != 0 && ISSPACE (*next_line))
++next_line;
return (next_line[0] == PARALLEL_SEPARATOR
@@ -4411,10 +4416,9 @@ subsym_substitute (char *line, int forced)
if (strstr (line, ".macro"))
return line;
- while (!is_end_of_line[(int) *ptr])
+ unsigned char current_char;
+ while (!is_end_of_line[(current_char = * (unsigned char *) ptr)])
{
- int current_char = *ptr;
-
/* Need to update this since LINE may have been modified. */
if (eval_line)
eval_end = strrchr (ptr, ',');
@@ -4734,9 +4738,13 @@ tic54x_start_line_hook (void)
char *replacement = NULL;
/* Work with a copy of the input line, including EOL char. */
- endp = input_line_pointer;
- while (!is_end_of_line[(int) *endp++])
- ;
+ for (endp = input_line_pointer; ; endp ++)
+ {
+ unsigned char c = * (unsigned char *) endp;
+ if (c == 0 || is_end_of_line [c])
+ break;
+ }
+
line = xmemdup0 (input_line_pointer, endp - input_line_pointer);
/* Scan ahead for parallel insns. */
@@ -5333,7 +5341,7 @@ tic54x_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
Don't allow labels to start with '.' */
int
-tic54x_start_label (int nul_char, int next_char)
+tic54x_start_label (char * label_start, int nul_char, int next_char)
{
char *rest;
@@ -5344,18 +5352,14 @@ tic54x_start_label (int nul_char, int next_char)
/* Disallow labels starting with "." */
if (next_char != ':')
{
- char *label = input_line_pointer;
-
- while (!is_end_of_line[(int) label[-1]])
- --label;
- if (*label == '.')
+ if (*label_start == '.')
{
- as_bad (_("Invalid label '%s'"), label);
+ as_bad (_("Invalid label '%s'"), label_start);
return 0;
}
}
- if (is_end_of_line[(int) next_char])
+ if (is_end_of_line[(unsigned char) next_char])
return 1;
rest = input_line_pointer;