From patchwork Sun Dec 31 08:57:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Kabatsayev X-Patchwork-Id: 25161 Received: (qmail 62543 invoked by alias); 31 Dec 2017 08:58:13 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 62473 invoked by uid 89); 31 Dec 2017 08:58:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-lf0-f68.google.com Received: from mail-lf0-f68.google.com (HELO mail-lf0-f68.google.com) (209.85.215.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 31 Dec 2017 08:58:03 +0000 Received: by mail-lf0-f68.google.com with SMTP id y71so588796lfd.12 for ; Sun, 31 Dec 2017 00:58:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=qOf5ZR6/Ss1YkKvd5AFHzcxsTKIoBiyWGm619r/vgTI=; b=KfqJ2FzFc92HUT5vy+Lrk/Q/TiWo1zeBeX8U8dHUN78sLJHFEP30L8bc1tVLdL2wZB EVmNkTnfAsi3KN5/JO9loyrSqueI08TyWfB6NDGfqhsBcm2uWRdObgCohaiaLPWhhqQh DQtzEv7OheN6ZXO5TCzHXn02XZcx8nbpKmba1CcPdskRhIFiR1L5KyHzlJNGc1q6mLVh xYvqKzVij9r2PiA4Db8NY5D8FRn5QfkyQJVaiK2QcnFgllCaRs7M6XAXj3R4ofSRh4m6 JIpJE+AswBUkuE6i/4PriqFDKSRc9Hq0m/24num4iFb6aglSCcaWOgPBu5AwfFcDqrkf gANQ== X-Gm-Message-State: AKGB3mLHJhdbfu9QBDw811sZGghXvQBFQdoms6qoFdRzGOwCkXZz8Oqd lHSt3oEWA8mWnPC5GAGVgULA4w== X-Google-Smtp-Source: ACJfBovqQ9AlvC9Ukv86gCZuvq5Q1jeIuNqtnVIhkPYpWE2cPSGXxXo18ojy6bz8aS94gCZ0tv8LlA== X-Received: by 10.46.66.216 with SMTP id h85mr24451034ljf.108.1514710680228; Sun, 31 Dec 2017 00:58:00 -0800 (PST) Received: from localhost.localdomain ([91.215.122.25]) by smtp.gmail.com with ESMTPSA id p17sm1028529lfe.51.2017.12.31.00.57.59 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 31 Dec 2017 00:57:59 -0800 (PST) From: Ruslan Kabatsayev To: gdb-patches@sourceware.org Cc: Ruslan Kabatsayev Subject: [PUSHED] Avoid indexing std::vector past the end Date: Sun, 31 Dec 2017 11:57:51 +0300 Message-Id: <1514710671-4183-1-git-send-email-b7.10110111@gmail.com> X-IsSubscribed: yes The code here wants to find address of an element, and often this element is one past the end of std::vector. Dereferencing that element leads to undefined behavior, so it's better to simply use pointer arithmetic instead of taking address of invalid dereference. gdb/ChangeLog: * psymtab.c (recursively_search_psymtabs): Use pointer arithmetic instead of dereferencing std::vector past the end. --- gdb/ChangeLog | 5 +++++ gdb/psymtab.c | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index edb3cd4..aaadf14 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2017-12-31 Ruslan Kabatsayev + + * psymtab.c (recursively_search_psymtabs): Use pointer arithmetic + instead of dereferencing std::vector past the end. + 2017-12-30 Simon Marchi * common/diagnostics.h diff --git a/gdb/psymtab.c b/gdb/psymtab.c index c87ef25..1271e18 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -1337,21 +1337,21 @@ recursively_search_psymtabs } partial_symbol **gbound - = &objfile->global_psymbols[ps->globals_offset + ps->n_global_syms]; + = objfile->global_psymbols.data () + ps->globals_offset + ps->n_global_syms; partial_symbol **sbound - = &objfile->static_psymbols[ps->statics_offset + ps->n_static_syms]; + = objfile->static_psymbols.data () + ps->statics_offset + ps->n_static_syms; partial_symbol **bound = gbound; /* Go through all of the symbols stored in a partial symtab in one loop. */ - partial_symbol **psym = &objfile->global_psymbols[ps->globals_offset]; + partial_symbol **psym = objfile->global_psymbols.data () + ps->globals_offset; while (keep_going) { if (psym >= bound) { if (bound == gbound && ps->n_static_syms != 0) { - psym = &objfile->static_psymbols[ps->statics_offset]; + psym = objfile->static_psymbols.data () + ps->statics_offset; bound = sbound; } else