PR28168: [CSKY] Fix stack overflow in disassembler
authorLifang Xia <lifang_xia@c-sky.com>
Tue, 10 Aug 2021 03:16:57 +0000 (11:16 +0800)
committerLifang Xia <lifang_xia@c-sky.com>
Fri, 13 Aug 2021 06:13:58 +0000 (14:13 +0800)
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.

gas/testsuite/gas/csky/pr28168.d [new file with mode: 0644]
gas/testsuite/gas/csky/pr28168.s [new file with mode: 0644]
gas/testsuite/gas/csky/v2_float_part2.d
opcodes/csky-dis.c

diff --git a/gas/testsuite/gas/csky/pr28168.d b/gas/testsuite/gas/csky/pr28168.d
new file mode 100644 (file)
index 0000000..0e7d6da
--- /dev/null
@@ -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 (file)
index 0000000..323eed4
--- /dev/null
@@ -0,0 +1 @@
+flrwd fr0, 8.721012e+150
index 78fa37bc0389868dc61b766e2284dcb0e7b0ac24..ecb6c156bdf75801fddf475fe23a932f14b3ed16 100644 (file)
@@ -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
index cdd911be09aa18eb1e385b0a51dc807a4bd1e6e5..cca8d364901b63d71a456d0d71ab9c0f4e5442f9 100644 (file)
@@ -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;