From: Lifang Xia Date: Tue, 10 Aug 2021 03:16:57 +0000 (+0800) Subject: PR28168: [CSKY] Fix stack overflow in disassembler X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1374be23274d0d569ca160b8172b2c02fc37becc;p=binutils-gdb.git PR28168: [CSKY] Fix stack overflow in disassembler PR 28168: Stack overflow with a large float. %f is not a goot choice for this. %f should be replaced with %.7g. gas/ * testsuite/gas/csky/pr28168.d: New testcase for PR 28168. * testsuite/gas/csky/pr28168.s: Likewise. * testsuite/gas/csky/v2_float_part2.d: Following the new format. * opcodes/csky-dis.c (csky_output_operand): %.7g replaces %f. --- diff --git a/gas/testsuite/gas/csky/pr28168.d b/gas/testsuite/gas/csky/pr28168.d new file mode 100644 index 00000000000..0e7d6dada0e --- /dev/null +++ b/gas/testsuite/gas/csky/pr28168.d @@ -0,0 +1,12 @@ +#as: -mcpu=ck807f +#objdump: -d + + +.*: +file format .*csky.* + +Disassembly of section \.text: + +00000000 <\.text>: +[ ]+[0-9a-f]+:[ ]+f4003910[ ]+flrwd[ ]+fr0, 8\.721012e\+150 +[ ]+[0-9a-f]+:[ ]+417f3259[ ]+\.long[ ]+0x417f3259 +[ ]+[0-9a-f]+:[ ]+5f45504f[ ]+\.long[ ]+0x5f45504f diff --git a/gas/testsuite/gas/csky/pr28168.s b/gas/testsuite/gas/csky/pr28168.s new file mode 100644 index 00000000000..323eed4eea3 --- /dev/null +++ b/gas/testsuite/gas/csky/pr28168.s @@ -0,0 +1 @@ +flrwd fr0, 8.721012e+150 diff --git a/gas/testsuite/gas/csky/v2_float_part2.d b/gas/testsuite/gas/csky/v2_float_part2.d index 78fa37bc038..ecb6c156bdf 100644 --- a/gas/testsuite/gas/csky/v2_float_part2.d +++ b/gas/testsuite/gas/csky/v2_float_part2.d @@ -6,15 +6,15 @@ Disassembly of section \.text: #... -\s*[0-9a-f]*:\s*f4003882\s*flrws\s*fr2,\s*3\.140000 -\s*[0-9a-f]*:\s*f50b1c02\s*fmovis\s*fr2,\s*1\.500000 -\s*[0-9a-f]*:\s*f51b1c02\s*fmovis\s*fr2,\s*-1\.500000 -\s*[0-9a-f]*:\s*f48a1c02\s*fmovis\s*fr2,\s*2\.500000 +\s*[0-9a-f]*:\s*f4003882\s*flrws\s*fr2,\s*3\.14 +\s*[0-9a-f]*:\s*f50b1c02\s*fmovis\s*fr2,\s*1\.5 +\s*[0-9a-f]*:\s*f51b1c02\s*fmovis\s*fr2,\s*-1\.5 +\s*[0-9a-f]*:\s*f48a1c02\s*fmovis\s*fr2,\s*2\.5 #... -\s*[0-9a-f]*:\s*f4003952\s*flrwd\s*fr2,\s*3\.140000 -\s*[0-9a-f]*:\s*f48a1e02\s*fmovid\s*fr2,\s*2\.500000 -\s*[0-9a-f]*:\s*f49a1e02\s*fmovid\s*fr2,\s*-2\.500000 -\s*[0-9a-f]*:\s*f51b1e02\s*fmovid\s*fr2,\s*-1\.500000 +\s*[0-9a-f]*:\s*f4003952\s*flrwd\s*fr2,\s*3\.14 +\s*[0-9a-f]*:\s*f48a1e02\s*fmovid\s*fr2,\s*2\.5 +\s*[0-9a-f]*:\s*f49a1e02\s*fmovid\s*fr2,\s*-2\.5 +\s*[0-9a-f]*:\s*f51b1e02\s*fmovid\s*fr2,\s*-1\.5 \s*[0-9a-f]*:\s*4048f5c3\s*\.long\s*0x4048f5c3 \s*[0-9a-f]*:\s*51eb851f\s*\.long\s*0x51eb851f \s*[0-9a-f]*:\s*40091eb8\s*\.long\s*0x40091eb8 diff --git a/opcodes/csky-dis.c b/opcodes/csky-dis.c index cdd911be09a..cca8d364901 100644 --- a/opcodes/csky-dis.c +++ b/opcodes/csky-dis.c @@ -565,7 +565,7 @@ csky_output_operand (char *str, struct operand const *oprnd, ? &floatformat_ieee_double_big : &floatformat_ieee_double_little), ibytes, &f); - sprintf (buf, "%f", f); + sprintf (buf, "%.7g", f); } else { @@ -645,7 +645,7 @@ csky_output_operand (char *str, struct operand const *oprnd, floatformat_to_double (&floatformat_ieee_double_little, valbytes, &fvalue); - sprintf (buf, "%f", fvalue); + sprintf (buf, "%.7g", fvalue); strcat (str, buf); break; } @@ -673,7 +673,7 @@ csky_output_operand (char *str, struct operand const *oprnd, float f = 0; memcpy (&f, &value, sizeof (float)); - sprintf (buf, "%f\t// imm9:%4d, imm4:%2d", f, imm8, imm4); + sprintf (buf, "%.7g\t// imm9:%4d, imm4:%2d", f, imm8, imm4); strcat (str, buf); break; @@ -702,7 +702,7 @@ csky_output_operand (char *str, struct operand const *oprnd, } double d = 0; memcpy (&d, &dvalue, sizeof (double)); - sprintf (buf, "%lf\t// imm9:%4ld, imm4:%2ld", d, (long) imm8, (long) imm4); + sprintf (buf, "%.7g\t// imm9:%4ld, imm4:%2ld", d, (long) imm8, (long) imm4); strcat (str, buf); break;