]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
libctf: error out on corrupt CTF with invalid header flags
authorNick Alcock <nick.alcock@oracle.com>
Wed, 3 Jun 2020 16:31:44 +0000 (17:31 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Wed, 22 Jul 2020 16:57:54 +0000 (17:57 +0100)
If corrupt CTF with invalid header flags is passed in, return the new
error ECTF_FLAGS.

include/
* ctf-api.h (ECTF_FLAGS): New.
(ECTF_NERR): Adjust.
* ctf.h (CTF_F_MAX): New.
libctf/
* ctf-open.c (ctf_bufopen_internal): Diagnose invalid flags.

include/ChangeLog
include/ctf-api.h
include/ctf.h
libctf/ChangeLog
libctf/ctf-open.c

index 9f47c8bff7741c61c7d8d4c707a29a14e31358df..8a48d009a69a4d082c8aaf956030280fc9ad3cbb 100644 (file)
@@ -1,3 +1,9 @@
+2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-api.h (ECTF_FLAGS): New.
+       (ECTF_NERR): Adjust.
+       * ctf.h (CTF_F_MAX): New.
+
 2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-api.h (ECTF_NEXT_END): New error.
index 47a1f732f0ebd54f9c00387d461aed68c5b17c18..760b1e46dc653b210f81bfc4d0400c1f0ba25901 100644 (file)
@@ -207,10 +207,11 @@ enum
    ECTF_NONREPRESENTABLE, /* Type not representable in CTF.  */
    ECTF_NEXT_END,      /* End of iteration.  */
    ECTF_NEXT_WRONGFUN, /* Wrong iteration function called.  */
-   ECTF_NEXT_WRONGFP   /* Iteration entity changed in mid-iterate.  */
+   ECTF_NEXT_WRONGFP,  /* Iteration entity changed in mid-iterate.  */
+   ECTF_FLAGS          /* CTF header contains flags unknown to libctf.  */
   };
 
-#define ECTF_NERR (ECTF_NEXT_WRONGFP - ECTF_BASE + 1)  /* Count of CTF errors.  */
+#define ECTF_NERR (ECTF_FLAGS - ECTF_BASE + 1) /* Count of CTF errors.  */
 
 /* The CTF data model is inferred to be the caller's data model or the data
    model of the given object, unless ctf_setmodel() is explicitly called.  */
index 168092b650e2ab025373d8ad8de5cee579278c5c..f251759afa1fb8d00a5826c604c9e4ae9c975277 100644 (file)
@@ -199,7 +199,8 @@ typedef struct ctf_header
 #define CTF_VERSION_3 4
 #define CTF_VERSION CTF_VERSION_3 /* Current version.  */
 
-#define CTF_F_COMPRESS 0x1     /* Data buffer is compressed by libctf.  */
+#define CTF_F_COMPRESS 0x1             /* Data buffer is compressed by libctf.  */
+#define CTF_F_MAX      CTF_F_COMPRESS  /* The greatest flag value in use.  */
 
 typedef struct ctf_lblent
 {
index 4a10f63d00c12c11f45ce128791fea413e97c633..45caf217cb22244ad586c26f80b5d8909f777a90 100644 (file)
@@ -1,3 +1,7 @@
+2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-open.c (ctf_bufopen_internal): Diagnose invalid flags.
+
 2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
 
        ctf-decls.h (ctf_qsort_compar_thunk): Fix arg passing.
index b7846bd001473bd9889ee2a293fecd36be64e578..f8eeaab0168bd4df0cc10d22b1b1c9ecbfabf5c5 100644 (file)
@@ -1384,6 +1384,9 @@ ctf_bufopen_internal (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect,
   if (pp->ctp_version < CTF_VERSION_3)
     hdrsz = sizeof (ctf_header_v2_t);
 
+  if (_libctf_unlikely_ (pp->ctp_flags > CTF_F_MAX))
+    return (ctf_set_open_errno (errp, ECTF_FLAGS));
+
   if (ctfsect->cts_size < hdrsz)
     return (ctf_set_open_errno (errp, ECTF_NOCTFBUF));