From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2041) id 11A643858D39; Wed, 8 Feb 2023 09:05:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 11A643858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675847158; bh=bZgfpcDrbwBDsycyMokVXL8LxiSYEAO9F2SRRFlyryA=; h=From:To:Subject:Date:From; b=Iw7M5S2Psl9l4Yigj37AYRCkjTd5vjtWgkvRNol2n0P+80eAa0Q+no4swIshFjwS9 wEqeRxf04Qr6GeeQUkM+9ro+S6mgX2mSWJX1IVVo/rGrn/jc9O+oT3j4WRlMe7mmMH RkSPHheIRNQO+HD5cxI/zHPHWZq23WBJ1bGb7wos= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Vladimir Mezentsev To: bfd-cvs@sourceware.org, gdb-cvs@sourceware.org Subject: [binutils-gdb] gprofng: fix SIGSEGV when processing unusual dwarf X-Act-Checkin: binutils-gdb X-Git-Author: Vladimir Mezentsev X-Git-Refname: refs/heads/master X-Git-Oldrev: 4170bc7ea846a14485e4729f1e2d707a04035c6f X-Git-Newrev: e02841b095a7797aaae1b064fb4b7acc2eb8d900 Message-Id: <20230208090558.11A643858D39@sourceware.org> Date: Wed, 8 Feb 2023 09:05:58 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3De02841b095a7= 797aaae1b064fb4b7acc2eb8d900 commit e02841b095a7797aaae1b064fb4b7acc2eb8d900 Author: Vladimir Mezentsev Date: Tue Feb 7 14:58:25 2023 -0800 gprofng: fix SIGSEGV when processing unusual dwarf =20 gprofng/ChangeLog 2023-02-07 Vladimir Mezentsev =20 PR gprofng/30093 * src/Dwarf.cc: add nullptr check. * src/DwarfLib.cc: Likewise. Diff: --- gprofng/src/Dwarf.cc | 16 ++++++++-------- gprofng/src/DwarfLib.cc | 20 ++++++++++++++------ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/gprofng/src/Dwarf.cc b/gprofng/src/Dwarf.cc index 1b33ae8f243..5485be7f796 100644 --- a/gprofng/src/Dwarf.cc +++ b/gprofng/src/Dwarf.cc @@ -606,12 +606,15 @@ Dwarf::archive_Dwarf (LoadObject *lo) { mod->hdrOffset =3D dwrCUs->size (); DwrLineRegs *lineReg =3D dwrCU->get_dwrLineReg (); - dwrCU->srcFiles =3D new Vector (VecSize (lineReg->file_na= mes)); - for (long i =3D 0, sz =3D VecSize (lineReg->file_names); i < sz; i++) + if (lineReg !=3D NULL) { - char *fname =3D lineReg->getPath (i + 1); - SourceFile *sf =3D mod->findSource (fname, true); - dwrCU->srcFiles->append (sf); + dwrCU->srcFiles =3D new Vector (VecSize (lineReg->fil= e_names)); + for (long i =3D 0, sz =3D VecSize (lineReg->file_names); i < sz; i+= +) + { + char *fname =3D lineReg->getPath (i + 1); + SourceFile *sf =3D mod->findSource (fname, true); + dwrCU->srcFiles->append (sf); + } } =20 Dwarf_cnt ctx; @@ -986,9 +989,6 @@ DwrCU::append_Function (Dwarf_cnt *ctx) if (lineno > 0) { func->setLineFirst (lineno); - if (dwrLineReg =3D=3D NULL) - dwrLineReg =3D new DwrLineRegs (new DwrSec (dwarf->debug_lineSec, - stmt_list_offset), comp_dir); int fileno =3D ((int) Dwarf_data (DW_AT_decl_file)) - 1; SourceFile *sf =3D ((fileno >=3D 0) && (fileno < VecSize (srcFiles))) ?= srcFiles->get (fileno) : module->getMainSrc (); diff --git a/gprofng/src/DwarfLib.cc b/gprofng/src/DwarfLib.cc index 4f86a78d1c8..e7130a7a438 100644 --- a/gprofng/src/DwarfLib.cc +++ b/gprofng/src/DwarfLib.cc @@ -31,6 +31,7 @@ #include "DbeArray.h" #include "DbeSession.h" =20 +#define NO_STMT_LIST ((uint64_t) -1) #define CASE_S(x) case x: s =3D (char *) #x; break =20 static char * @@ -1557,8 +1558,11 @@ DwrLineRegs::getPath (int fn) if (*dir !=3D '/') { // not absolute char *s =3D include_directories->fetch (0); - sb.append (s); - sb.append ('/'); + if (s !=3D NULL && *s !=3D 0) + { + sb.append (s); + sb.append ('/'); + } } sb.append (dir); sb.append ('/'); @@ -1590,7 +1594,7 @@ DwrCU::DwrCU (Dwarf *_dwarf) abbrevTable =3D NULL; dwrInlinedSubrs =3D NULL; srcFiles =3D NULL; - stmt_list_offset =3D 0; + stmt_list_offset =3D NO_STMT_LIST; dwrLineReg =3D NULL; isMemop =3D false; isGNU =3D false; @@ -1857,7 +1861,9 @@ DwrCU::parse_cu_header (LoadObject *lo) char *name =3D Dwarf_string (DW_AT_name); if (name =3D=3D NULL) name =3D NTXT ("UnnamedUnit"); - stmt_list_offset =3D Dwarf_data (DW_AT_stmt_list); + int64_t v; + if (read_data_attr(DW_AT_stmt_list, &v) =3D=3D DW_DLV_OK) + stmt_list_offset =3D v; comp_dir =3D dbe_strdup (Dwarf_string (DW_AT_comp_dir)); char *dir_name =3D comp_dir ? StrChr (comp_dir, ':') : NULL; char *orig_name =3D Dwarf_string (DW_AT_SUN_original_name); @@ -2073,6 +2079,8 @@ DwrCU::map_dwarf_lines (Module *mod) Stabs::is_fortran (mod->lang_code)); } } + if (lineReg =3D=3D NULL) + return; Vector *lines =3D lineReg->get_lines (); =20 Include *includes =3D new Include; @@ -2083,7 +2091,7 @@ DwrCU::map_dwarf_lines (Module *mod) for (long i =3D 0, sz =3D VecSize (lines); i < sz; i++) { DwrLine *dwrLine =3D lines->get (i); - char *filename =3D dwrLineReg->getPath (dwrLine->file); + char *filename =3D lineReg->getPath (dwrLine->file); if (filename =3D=3D NULL) continue; uint64_t pc =3D dwrLine->address; @@ -2123,7 +2131,7 @@ DwrCU::map_dwarf_lines (Module *mod) DwrLineRegs * DwrCU::get_dwrLineReg () { - if (dwrLineReg =3D=3D NULL) + if (dwrLineReg =3D=3D NULL && stmt_list_offset !=3D NO_STMT_LIST) dwrLineReg =3D new DwrLineRegs (new DwrSec (dwarf->debug_lineSec, stmt_list_offset), comp_dir); return dwrLineReg;