Eric Pouech : dbghelp: Check correctness of type (esp. in case of unknown ones).

Alexandre Julliard julliard at winehq.org
Fri Sep 3 16:25:28 CDT 2021


Module: wine
Branch: master
Commit: c8fede5efbbb2e64ad8c6581fecf47dc06c7916f
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=c8fede5efbbb2e64ad8c6581fecf47dc06c7916f

Author: Eric Pouech <eric.pouech at gmail.com>
Date:   Thu Sep  2 11:22:44 2021 +0200

dbghelp: Check correctness of type (esp. in case of unknown ones).

Since with the unknown type entry, we can end up with types which don't
match the expected symt->tag, we need to check before the conversions.

Signed-off-by: Eric Pouech <eric.pouech at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dbghelp/dbghelp_private.h |  5 +++++
 dlls/dbghelp/dwarf.c           | 22 +++++++++++++---------
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h
index 2b0365bc386..eb2b53e947a 100644
--- a/dlls/dbghelp/dbghelp_private.h
+++ b/dlls/dbghelp/dbghelp_private.h
@@ -151,6 +151,11 @@ struct symt_ht
     struct hash_table_elt       hash_elt;        /* if global symbol or type */
 };
 
+static inline BOOL symt_check_tag(const struct symt* s, enum SymTagEnum tag)
+{
+    return s && s->tag == tag;
+}
+
 /* lexical tree */
 struct symt_block
 {
diff --git a/dlls/dbghelp/dwarf.c b/dlls/dbghelp/dwarf.c
index 1876f573cf9..ee73abdf378 100644
--- a/dlls/dbghelp/dwarf.c
+++ b/dlls/dbghelp/dwarf.c
@@ -1439,7 +1439,8 @@ static struct symt* dwarf2_parse_udt_type(dwarf2_parse_context_t* ctx,
             break;
         case DW_TAG_member:
             /* FIXME: should I follow the sibling stuff ?? */
-            dwarf2_parse_udt_member(ctx, child, (struct symt_udt*)di->symt);
+            if (symt_check_tag(di->symt, SymTagUDT))
+                dwarf2_parse_udt_member(ctx, child, (struct symt_udt*)di->symt);
             break;
         case DW_TAG_enumeration_type:
             dwarf2_parse_enumeration_type(ctx, child);
@@ -1527,7 +1528,8 @@ static struct symt* dwarf2_parse_enumeration_type(dwarf2_parse_context_t* ctx,
         switch (child->abbrev->tag)
         {
         case DW_TAG_enumerator:
-            dwarf2_parse_enumerator(ctx, child, (struct symt_enum*)di->symt);
+            if (symt_check_tag(di->symt, SymTagEnum))
+                dwarf2_parse_enumerator(ctx, child, (struct symt_enum*)di->symt);
             break;
         default:
             FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
@@ -1683,7 +1685,7 @@ static void dwarf2_parse_variable(dwarf2_subprogram_t* subpgm,
             WARN("dropping global variable %s which has been optimized away\n", debugstr_a(name.u.string));
         }
     }
-    if (is_pmt && subpgm->func && subpgm->func->type)
+    if (is_pmt && subpgm->func && symt_check_tag(subpgm->func->type, SymTagFunctionType))
         symt_add_function_signature_parameter(subpgm->ctx->module,
                                               (struct symt_function_signature*)subpgm->func->type,
                                               param_type);
@@ -2129,10 +2131,12 @@ static void dwarf2_set_line_number(struct module* module, ULONG_PTR address,
 
     TRACE("%s %lx %s %u\n",
           debugstr_w(module->module.ModuleName), address, debugstr_a(source_get(module, *psrc)), line);
-    if (!(symt = symt_find_nearest(module, address)) ||
-        symt->symt.tag != SymTagFunction) return;
-    func = (struct symt_function*)symt;
-    symt_add_func_line(module, func, *psrc, line, address - func->address);
+    symt = symt_find_nearest(module, address);
+    if (symt && symt_check_tag(&symt->symt, SymTagFunction))
+    {
+        func = (struct symt_function*)symt;
+        symt_add_func_line(module, func, *psrc, line, address - func->address);
+    }
 }
 
 static BOOL dwarf2_parse_line_numbers(const dwarf2_section_t* sections,
@@ -2466,7 +2470,7 @@ static enum location_error loc_compute_frame(struct process* pcs,
     for (i=0; i<vector_length(&func->vchildren); i++)
     {
         psym = vector_at(&func->vchildren, i);
-        if ((*psym)->tag == SymTagCustom)
+        if (psym && symt_check_tag(*psym, SymTagCustom))
         {
             pframe = &((struct symt_hierarchy_point*)*psym)->loc;
 
@@ -3279,7 +3283,7 @@ static void dwarf2_location_compute(struct process* pcs,
     int                         err;
     dwarf2_traverse_context_t   lctx;
 
-    if (!func->container || func->container->tag != SymTagCompiland)
+    if (!func || !symt_check_tag(func->container, SymTagCompiland))
     {
         WARN("We'd expect function %s's container to exist and be a compiland\n", debugstr_a(func->hash_elt.name));
         err = loc_err_internal;




More information about the wine-cvs mailing list