From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id 5B5463858C53 for ; Wed, 23 Aug 2023 01:39:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5B5463858C53 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-565e54cb93aso2610202a12.3 for ; Tue, 22 Aug 2023 18:39:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692754778; x=1693359578; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=6R6K9QTpkn9tzrJUj2aa1+zIgvQSboQ0NioznhpiDFQ=; b=XH9E9PaMuaCgR6ylmH3paqutLVDecJubZECXA2633o5k2TuB8IvszN5nwbKGN7gzUR /tSJd3DTr0e3GJ5uEimnx8aMevDW8ZyCDlkBvjpprUirEo2jDWh/PNKniAXl00dP8uRh 177xUWj+b7HmipLfuWPGYym0BOTWaMnPmJ5P85Ujc8R1ptxRRc75O1AGrxeV7OA1yT+7 t3fvuDzA8gkNug1iNiVNW2hzJPM5viVW/lUTWLImBOLH26kudfbxyMfh9zFbiVMNcXfx m7TDC5LTxQx4a22UsJwESCY6rhVcg7EvkWowI+R5bZvi/LFuiYJ4Jeo1vsZ7H/ChE8Tn ZQGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692754778; x=1693359578; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6R6K9QTpkn9tzrJUj2aa1+zIgvQSboQ0NioznhpiDFQ=; b=lix8lyuo7lssS86ty3peUb8M5scWKR66cKl+RjxDgIeozqWRwf5dOOhlP5okx14fZz MW0rfblXJXQziPUN5vpC37CQRK0QmGR7sQygs0sGzP4vH6zp3/tPLywBdDkhSAXXw3Yk 0zJz614hHGy1+CRqDe7x9j9AOODYqlU0SkNSXetcWPgWZ7/SfNLnn9u/axAsOrHiAI56 +6EwDFFIXq+TBABN5C5TaAz8YgQ9x+hC4VY40o+5Skgt/daSyD+DOeZkK9f8wbJ1jZI2 XS4Mv8RcLsOjlG5hF/NI133OKzqDtjLJXSwvwJsq67HmSrAhXGIwyBAfP87vgsWRXlbR cNew== X-Gm-Message-State: AOJu0YwJHnhpILS5goT6A0ye2WiOdnu4R1DjsYaad9LzNGlZaA4eQigX pT4NaCKpj1K6tFzxsdqF5qNiC3RHiypFNA== X-Google-Smtp-Source: AGHT+IGozEglSZK/uUsb7VaKIyBjyrLFpZCJtHx85LnO6Pc5kpaN8n/lCiEjL5tWWZEfZiHmh48Z4g== X-Received: by 2002:a05:6a20:9481:b0:148:1185:8802 with SMTP id hs1-20020a056a20948100b0014811858802mr7712023pzb.30.1692754777826; Tue, 22 Aug 2023 18:39:37 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:ead0:eed5:cfa5:cc5d]) by smtp.gmail.com with ESMTPSA id j8-20020a170902690800b001bc56c1a384sm9603169plk.277.2023.08.22.18.39.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 18:39:37 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id D503F11423E0; Wed, 23 Aug 2023 11:09:34 +0930 (ACST) Date: Wed, 23 Aug 2023 11:09:34 +0930 From: Alan Modra To: gdb-patches@sourceware.org Subject: gdb: bfd_get_symbol_leading_char vs. "" Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3033.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Some places matching the first char of a string against bfd_get_symbol_leading_char, which may be zero, didn't check for "". This could lead to accesses past the end of the string and potential buffer overruns. Fix that, and also get rid of a stupid optimisation in dbxread when looking for "__DYNAMIC" that also might access past the end of a string. diff --git a/gdb/coffread.c b/gdb/coffread.c index 13610998ad7..7998327fdaf 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -64,8 +64,8 @@ static const registry::key coff_objfile_data_key; /* Translate an external name string into a user-visible name. */ #define EXTERNAL_NAME(string, abfd) \ - (string[0] == bfd_get_symbol_leading_char (abfd) \ - ? string + 1 : string) + (*string && *string == bfd_get_symbol_leading_char (abfd) \ + ? string + 1 : string) /* To be an sdb debug type, type must have at least a basic or primary derived type. Using this rather than checking against T_NULL is diff --git a/gdb/dbxread.c b/gdb/dbxread.c index 7cddf6586ed..4c585efd192 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -479,14 +479,15 @@ record_minimal_symbol (minimal_symbol_reader &reader, Record it as global even if it's local, not global, so lookup_minimal_symbol can find it. We don't check symbol_leading_char because for SunOS4 it always is '_'. */ - if (name[8] == 'C' && strcmp ("__DYNAMIC", name) == 0) + if (strcmp ("__DYNAMIC", name) == 0) ms_type = mst_data; /* Same with virtual function tables, both global and static. */ { const char *tempstring = name; - if (tempstring[0] == bfd_get_symbol_leading_char (objfile->obfd.get ())) + if (*tempstring + && *tempstring == bfd_get_symbol_leading_char (objfile->obfd.get ())) ++tempstring; if (is_vtable_name (tempstring)) ms_type = mst_data; @@ -2254,7 +2255,8 @@ read_ofile_symtab (struct objfile *objfile, legacy_psymtab *pst) processing_gcc_compilation = 1; else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0) processing_gcc_compilation = 2; - if (tempstring[0] == bfd_get_symbol_leading_char (symfile_bfd)) + if (*tempstring + && *tempstring == bfd_get_symbol_leading_char (symfile_bfd)) ++tempstring; if (startswith (tempstring, "__gnu_compiled")) processing_gcc_compilation = 2; diff --git a/gdb/machoread.c b/gdb/machoread.c index 5154d1a31a3..615e08c6afa 100644 --- a/gdb/machoread.c +++ b/gdb/machoread.c @@ -394,7 +394,8 @@ macho_resolve_oso_sym_with_minsym (struct objfile *main_objfile, asymbol *sym) struct bound_minimal_symbol msym; const char *name = sym->name; - if (name[0] == bfd_get_symbol_leading_char (main_objfile->obfd.get ())) + if (*name + && *name == bfd_get_symbol_leading_char (main_objfile->obfd.get ())) ++name; msym = lookup_minimal_symbol (name, NULL, main_objfile); if (msym.minsym == NULL) -- Alan Modra Australia Development Lab, IBM