aboutsummaryrefslogtreecommitdiff
path: root/gas/listing.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2021-02-09 12:53:32 +0000
committerNick Clifton <nickc@redhat.com>2021-02-09 12:53:32 +0000
commit4a68fcd7f7da92d47f0f41df15fea30f790ed06c (patch)
treefea666ca189d56117d8ff25a6dbb2a53738f3553 /gas/listing.c
parent52563b0f1c5516930b4507861d261529483a5e83 (diff)
downloadgdb-4a68fcd7f7da92d47f0f41df15fea30f790ed06c.zip
gdb-4a68fcd7f7da92d47f0f41df15fea30f790ed06c.tar.gz
gdb-4a68fcd7f7da92d47f0f41df15fea30f790ed06c.tar.bz2
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.
Diffstat (limited to 'gas/listing.c')
-rw-r--r--gas/listing.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/gas/listing.c b/gas/listing.c
index 6304aef..f86fb00 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 ();
}