aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ld/testsuite/ld-ctf/diag-cttname-invalid.s2
-rw-r--r--ld/testsuite/ld-ctf/diag-cttname-null.s2
-rw-r--r--ld/testsuite/ld-ctf/diag-cuname.s2
-rw-r--r--ld/testsuite/ld-ctf/diag-parlabel.s2
-rw-r--r--ld/testsuite/ld-ctf/diag-parname.s2
-rw-r--r--ld/testsuite/ld-ctf/diag-strlen-invalid.d5
-rw-r--r--ld/testsuite/ld-ctf/diag-strlen-invalid.s44
-rw-r--r--libctf/ctf-open.c45
8 files changed, 83 insertions, 21 deletions
diff --git a/ld/testsuite/ld-ctf/diag-cttname-invalid.s b/ld/testsuite/ld-ctf/diag-cttname-invalid.s
index dbfdd21..f025254 100644
--- a/ld/testsuite/ld-ctf/diag-cttname-invalid.s
+++ b/ld/testsuite/ld-ctf/diag-cttname-invalid.s
@@ -15,7 +15,7 @@
.long 0x8
.long 0x10
.long 0x40
- .long 0x42
+ .long 0x37
.long 0x1
.long 0x7
.long 0x7
diff --git a/ld/testsuite/ld-ctf/diag-cttname-null.s b/ld/testsuite/ld-ctf/diag-cttname-null.s
index ad6ce60..f3ba212 100644
--- a/ld/testsuite/ld-ctf/diag-cttname-null.s
+++ b/ld/testsuite/ld-ctf/diag-cttname-null.s
@@ -15,7 +15,7 @@
.long 0x8
.long 0x10
.long 0x40
- .long 0x42
+ .long 0x37
.long 0x1
.long 0x7
.long 0x7
diff --git a/ld/testsuite/ld-ctf/diag-cuname.s b/ld/testsuite/ld-ctf/diag-cuname.s
index dcdbd62..95f3d72 100644
--- a/ld/testsuite/ld-ctf/diag-cuname.s
+++ b/ld/testsuite/ld-ctf/diag-cuname.s
@@ -15,7 +15,7 @@
.long 0x8
.long 0x10
.long 0x40
- .long 0x42
+ .long 0x37
.long 0x1
.long 0x7
.long 0x7
diff --git a/ld/testsuite/ld-ctf/diag-parlabel.s b/ld/testsuite/ld-ctf/diag-parlabel.s
index e0ce57c..b31fb81 100644
--- a/ld/testsuite/ld-ctf/diag-parlabel.s
+++ b/ld/testsuite/ld-ctf/diag-parlabel.s
@@ -15,7 +15,7 @@
.long 0x8
.long 0x10
.long 0x40
- .long 0x42
+ .long 0x37
.long 0x1
.long 0x7
.long 0x7
diff --git a/ld/testsuite/ld-ctf/diag-parname.s b/ld/testsuite/ld-ctf/diag-parname.s
index da30e4a..d30178d 100644
--- a/ld/testsuite/ld-ctf/diag-parname.s
+++ b/ld/testsuite/ld-ctf/diag-parname.s
@@ -15,7 +15,7 @@
.long 0x8
.long 0x10
.long 0x40
- .long 0x42
+ .long 0x37
.long 0x1
.long 0x7
.long 0x7
diff --git a/ld/testsuite/ld-ctf/diag-strlen-invalid.d b/ld/testsuite/ld-ctf/diag-strlen-invalid.d
new file mode 100644
index 0000000..8a7b69b
--- /dev/null
+++ b/ld/testsuite/ld-ctf/diag-strlen-invalid.d
@@ -0,0 +1,5 @@
+#as:
+#source: diag-strlen-invalid.s
+#ld: -shared
+#name: Diagnostics - String offset invalid.
+#warning: .* byte long CTF dictionary overruns .* byte long CTF section
diff --git a/ld/testsuite/ld-ctf/diag-strlen-invalid.s b/ld/testsuite/ld-ctf/diag-strlen-invalid.s
new file mode 100644
index 0000000..dbfdd21
--- /dev/null
+++ b/ld/testsuite/ld-ctf/diag-strlen-invalid.s
@@ -0,0 +1,44 @@
+ .file "A.c"
+ .section .ctf,"",@progbits
+.Lctf0:
+ .2byte 0xdff2
+ .byte 0x4
+ .byte 0
+ .long 0
+ .long 0
+ .long 0x9
+ .long 0
+ .long 0
+ .long 0x4
+ .long 0x4
+ .long 0x8
+ .long 0x8
+ .long 0x10
+ .long 0x40
+ .long 0x42
+ .long 0x1
+ .long 0x7
+ .long 0x7
+ .long 0x1
+ .long 0xff00
+ .long 0x1a000001
+ .long 0x8
+ .long 0x5
+ .long 0
+ .long 0x3
+ .long 0x3
+ .long 0x26000000
+ .long 0x6
+ .long 0
+ .long 0xe000000
+ .long 0x2
+ .ascii "\0"
+ .ascii "A\0"
+ .ascii "B\0"
+ .ascii "b\0"
+ .ascii "a\0"
+ .ascii "/usr/src/binutils-gdb/ld/testsuite/ld-ctf/A.c\0"
+ .text
+ .comm a,8,8
+ .ident "GCC: (GNU) 8.3.1 20191121 (Red Hat 8.3.1-5.0.1)"
+ .section .note.GNU-stack,"",@progbits
diff --git a/libctf/ctf-open.c b/libctf/ctf-open.c
index c7ca37e..3f8d336 100644
--- a/libctf/ctf-open.c
+++ b/libctf/ctf-open.c
@@ -1517,26 +1517,39 @@ ctf_bufopen_internal (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect,
goto bad;
}
}
- else if (foreign_endian)
+ else
{
- if ((fp->ctf_base = malloc (fp->ctf_size)) == NULL)
+ if (_libctf_unlikely_ (ctfsect->cts_size < hdrsz + fp->ctf_size))
{
- err = ECTF_ZALLOC;
+ ctf_err_warn (NULL, 0, ECTF_CORRUPT,
+ _("%lu byte long CTF dictionary overruns %lu byte long CTF section"),
+ (unsigned long) ctfsect->cts_size,
+ (unsigned long) (hdrsz + fp->ctf_size));
+ err = ECTF_CORRUPT;
goto bad;
}
- fp->ctf_dynbase = fp->ctf_base;
- memcpy (fp->ctf_base, ((unsigned char *) ctfsect->cts_data) + hdrsz,
- fp->ctf_size);
- fp->ctf_buf = fp->ctf_base;
- }
- else
- {
- /* We are just using the section passed in -- but its header may be an old
- version. Point ctf_buf past the old header, and never touch it
- again. */
- fp->ctf_base = (unsigned char *) ctfsect->cts_data;
- fp->ctf_dynbase = NULL;
- fp->ctf_buf = fp->ctf_base + hdrsz;
+
+ if (foreign_endian)
+ {
+ if ((fp->ctf_base = malloc (fp->ctf_size)) == NULL)
+ {
+ err = ECTF_ZALLOC;
+ goto bad;
+ }
+ fp->ctf_dynbase = fp->ctf_base;
+ memcpy (fp->ctf_base, ((unsigned char *) ctfsect->cts_data) + hdrsz,
+ fp->ctf_size);
+ fp->ctf_buf = fp->ctf_base;
+ }
+ else
+ {
+ /* We are just using the section passed in -- but its header may
+ be an old version. Point ctf_buf past the old header, and
+ never touch it again. */
+ fp->ctf_base = (unsigned char *) ctfsect->cts_data;
+ fp->ctf_dynbase = NULL;
+ fp->ctf_buf = fp->ctf_base + hdrsz;
+ }
}
/* Once we have uncompressed and validated the CTF data buffer, we can