ld-checks: tweak overflow checks.
[deliverable/binutils-gdb.git] / gdb / dtrace-probe.c
index a6544ba1c98c0c5dd369f15354fb8b1713fb5c04..122f8ded91b6fcf630c6a306aa2ffdb754557d22 100644 (file)
@@ -1,6 +1,6 @@
 /* DTrace probe support for GDB.
 
-   Copyright (C) 2014-2015 Free Software Foundation, Inc.
+   Copyright (C) 2014-2017 Free Software Foundation, Inc.
 
    Contributed by Oracle, Inc.
 
@@ -43,7 +43,7 @@
 
 /* Forward declaration.  */
 
-static const struct probe_ops dtrace_probe_ops;
+extern const struct probe_ops dtrace_probe_ops;
 
 /* The following structure represents a single argument for the
    probe.  */
@@ -386,8 +386,8 @@ dtrace_process_dof_probe (struct objfile *objfile,
     {
       uint32_t probe_offset
        = ((uint32_t *) offtab)[DOF_UINT (dof, probe->dofpr_offidx) + i];
-      struct dtrace_probe *ret
-       = obstack_alloc (&objfile->per_bfd->storage_obstack, sizeof (*ret));
+      struct dtrace_probe *ret =
+       XOBNEW (&objfile->per_bfd->storage_obstack, struct dtrace_probe);
 
       ret->p.pops = &dtrace_probe_ops;
       ret->p.arch = gdbarch;
@@ -413,8 +413,11 @@ dtrace_process_dof_probe (struct objfile *objfile,
       for (j = 0; j < ret->probe_argc; j++)
        {
          struct dtrace_probe_arg arg;
-         struct expression *expr;
+         expression_up expr;
 
+         /* Set arg.expr to ensure all fields in expr are initialized and
+            the compiler will not warn when arg is used.  */
+         arg.expr = NULL;
          arg.type_str = xstrdup (p);
 
          /* Use strtab_size as a sentinel.  */
@@ -424,8 +427,17 @@ dtrace_process_dof_probe (struct objfile *objfile,
             this does not work then we set the type to `long
             int'.  */
           arg.type = builtin_type (gdbarch)->builtin_long;
-         expr = parse_expression (arg.type_str);
-         if (expr->elts[0].opcode == OP_TYPE)
+
+         TRY
+           {
+             expr = parse_expression_with_language (arg.type_str, language_c);
+           }
+         CATCH (ex, RETURN_MASK_ERROR)
+           {
+           }
+         END_CATCH
+
+         if (expr != NULL && expr->elts[0].opcode == OP_TYPE)
            arg.type = expr->elts[1].type;
 
          VEC_safe_push (dtrace_probe_arg_s, ret->args, &arg);
@@ -450,8 +462,6 @@ static void
 dtrace_process_dof (asection *sect, struct objfile *objfile,
                    VEC (probe_p) **probesp, struct dtrace_dof_hdr *dof)
 {
-  bfd *abfd = objfile->obfd;
-  int size = bfd_get_arch_size (abfd) / 8;
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct dtrace_dof_sect *section;
   int i;
@@ -506,6 +516,14 @@ dtrace_process_dof (asection *sect, struct objfile *objfile,
        unsigned int entsize = DOF_UINT (dof, probes_s->dofs_entsize);
        int num_probes;
 
+       if (DOF_UINT (dof, section->dofs_size)
+           < sizeof (struct dtrace_dof_provider))
+         {
+           /* The section is smaller than expected, so do not use it.
+              This has been observed on x86-solaris 10.  */
+           goto invalid_dof_data;
+         }
+
        /* Very, unlikely, but could crash gdb if not handled
           properly.  */
        if (entsize == 0)
@@ -617,17 +635,18 @@ dtrace_get_probes (VEC (probe_p) **probesp, struct objfile *objfile)
     {
       if (elf_section_data (sect)->this_hdr.sh_type == SHT_SUNW_dof)
        {
-         struct dtrace_dof_hdr *dof;
+         bfd_byte *dof;
 
          /* Read the contents of the DOF section and then process it to
             extract the information of any probe defined into it.  */
-         if (!bfd_malloc_and_get_section (abfd, sect, (bfd_byte **) &dof))
+         if (!bfd_malloc_and_get_section (abfd, sect, &dof))
            complaint (&symfile_complaints,
                       _("could not obtain the contents of"
                         "section '%s' in objfile `%s'."),
                       sect->name, abfd->filename);
       
-         dtrace_process_dof (sect, objfile, probesp, dof);
+         dtrace_process_dof (sect, objfile, probesp,
+                             (struct dtrace_dof_hdr *) dof);
          xfree (dof);
        }
     }
@@ -861,7 +880,7 @@ dtrace_disable_probe (struct probe *probe)
 
 /* DTrace probe_ops.  */
 
-static const struct probe_ops dtrace_probe_ops =
+const struct probe_ops dtrace_probe_ops =
 {
   dtrace_probe_is_linespec,
   dtrace_get_probes,
This page took 0.025746 seconds and 4 git commands to generate.