From 4a68fcd7f7da92d47f0f41df15fea30f790ed06c Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Tue, 9 Feb 2021 12:53:32 +0000 Subject: [PATCH] Prevent a bad .Psize expression from triggering a memory access violation. PR 27384 * listing.c (listing_psize): Check the result of the width expression before assigning it to paper_width. * testsuite/gas/all/pr27384.s: New test source file. * testsuite/gas/all/pr27384.d: New test control file. * testsuite/gas/all/pr27384.err: Expected errors from new test. * testsuite/gas/all/gas.exp: Run the new test. --- gas/ChangeLog | 10 ++++++++++ gas/listing.c | 22 +++++++++++++++++++++- gas/testsuite/gas/all/gas.exp | 1 + gas/testsuite/gas/all/pr27384.d | 4 ++++ gas/testsuite/gas/all/pr27384.err | 4 ++++ gas/testsuite/gas/all/pr27384.s | 4 ++++ 6 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 gas/testsuite/gas/all/pr27384.d create mode 100644 gas/testsuite/gas/all/pr27384.err create mode 100644 gas/testsuite/gas/all/pr27384.s diff --git a/gas/ChangeLog b/gas/ChangeLog index b4088cf0110..8ab1d35d144 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,13 @@ +2021-02-09 Nick Clifton + + PR 27384 + * listing.c (listing_psize): Check the result of the width + expression before assigning it to paper_width. + * testsuite/gas/all/pr27384.s: New test source file. + * testsuite/gas/all/pr27384.d: New test control file. + * testsuite/gas/all/pr27384.err: Expected errors from new test. + * testsuite/gas/all/gas.exp: Run the new test. + 2021-02-09 Nick Clifton PR 27355 diff --git a/gas/listing.c b/gas/listing.c index 6304aefd08b..f86fb000f93 100644 --- a/gas/listing.c +++ b/gas/listing.c @@ -484,6 +484,8 @@ buffer_line (file_info_type *file, char *line, unsigned int size) if (file->at_end) return ""; +if (size == (unsigned int) -7) exit (1); + /* Check the cache and see if we last used this file. */ if (!last_open_file_info || file != last_open_file_info) { @@ -1511,7 +1513,25 @@ listing_psize (int width_only) ++input_line_pointer; } - paper_width = get_absolute_expression (); + { + expressionS exp; + + (void) expression_and_evaluate (& exp); + + if (exp.X_op == O_constant) + { + offsetT new_width = exp.X_add_number; + + if (new_width > 7) + paper_width = new_width; + else + as_bad (_("new paper width is too small")); + } + else if (exp.X_op != O_absent) + as_bad (_("bad or irreducible expression for paper width")); + else + as_bad (_("missing expression for paper width")); + } demand_empty_rest_of_line (); } diff --git a/gas/testsuite/gas/all/gas.exp b/gas/testsuite/gas/all/gas.exp index ee24c0d5b6a..af36b095e85 100644 --- a/gas/testsuite/gas/all/gas.exp +++ b/gas/testsuite/gas/all/gas.exp @@ -469,3 +469,4 @@ gas_test "pr23938.s" "" "" ".xstabs" run_dump_test "nop" run_dump_test "asciz" +run_dump_test "pr27384" diff --git a/gas/testsuite/gas/all/pr27384.d b/gas/testsuite/gas/all/pr27384.d new file mode 100644 index 00000000000..5426c918c25 --- /dev/null +++ b/gas/testsuite/gas/all/pr27384.d @@ -0,0 +1,4 @@ +#as: -a +#error_output: pr27384.err +# The metag target does not support the .Psize directive. +#notarget: metag-* rx-* diff --git a/gas/testsuite/gas/all/pr27384.err b/gas/testsuite/gas/all/pr27384.err new file mode 100644 index 00000000000..2d5954f91ed --- /dev/null +++ b/gas/testsuite/gas/all/pr27384.err @@ -0,0 +1,4 @@ +.*pr27384.s: Assembler messages: +.*pr27384.s:2: Error: bad or irreducible absolute expression +.*pr27384.s:2: Error: new paper width is too small +#pass diff --git a/gas/testsuite/gas/all/pr27384.s b/gas/testsuite/gas/all/pr27384.s new file mode 100644 index 00000000000..6d831b0d5f9 --- /dev/null +++ b/gas/testsuite/gas/all/pr27384.s @@ -0,0 +1,4 @@ + .nop + .Psize f,-7 + .nop + -- 2.30.2