From patchwork Sat Dec 30 19:31:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Kabatsayev X-Patchwork-Id: 25154 Received: (qmail 111079 invoked by alias); 30 Dec 2017 19:31:53 -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 111067 invoked by uid 89); 30 Dec 2017 19:31:52 -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=Hx-languages-length:1552 X-HELO: mail-lf0-f66.google.com Received: from mail-lf0-f66.google.com (HELO mail-lf0-f66.google.com) (209.85.215.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 30 Dec 2017 19:31:51 +0000 Received: by mail-lf0-f66.google.com with SMTP id m20so37732362lfi.6 for ; Sat, 30 Dec 2017 11:31:50 -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=zFlrti0z9+mJ4owke+dw2jyS/EDJ0buMTUZ0n+yFmBM=; b=A9QgAhbZ8pnKIC5daH2Tlo6GcCKm6g3bc23cxQgUET/3tPsUz9slw6Loq2ZFBtCvOG TaSxXg+E7vwv+mSW2z4qw74kpahWQ/ksoCfdXjcfCzPyXj4wKT9G9N4K1pk38s+jrTOz rYL2Y05CcMQ4IoCrJxQHiFvcQPJfWrQE9Cexv5yJLRorW7AfONiFgmRBGWkNQmhY23Lz rM+yStNWgsGEnVm0oO4pgzV9Aa6vNT2ZgfU6S8lRAmdlG6hGzt6G2Mk38srkH/XDGZ9T 1k9cWOSkRZFCUL20dJEKlyqUI0ohJH/Vt2XV1ohWermdhxqB5HQgLL360yzXLHxMeoZw ym5A== X-Gm-Message-State: AKGB3mJckSDDAzwZEwqfbf0OBdpT1NbsfHkvjIc6HT77nNQrxu3Egm/Y vGNaigHjEQwB1WHrzhUrhx4Bag== X-Google-Smtp-Source: ACJfBouCBhexcdpmVJhPSorOIkbtxtQPEzRgkfVxPB1r/nFjpkqZT2pdWJMrhwIz/PG2KcHA1m91gg== X-Received: by 10.46.68.11 with SMTP id r11mr22755035lja.1.1514662308834; Sat, 30 Dec 2017 11:31:48 -0800 (PST) Received: from localhost.localdomain ([91.215.122.25]) by smtp.gmail.com with ESMTPSA id o9sm3127336lfb.64.2017.12.30.11.31.47 (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 30 Dec 2017 11:31:47 -0800 (PST) From: Ruslan Kabatsayev To: gdb-patches@sourceware.org Cc: Ruslan Kabatsayev Subject: [PATCH] Avoid indexing std::vector past the end Date: Sat, 30 Dec 2017 22:31:13 +0300 Message-Id: <1514662273-27858-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/psymtab.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gdb/psymtab.c b/gdb/psymtab.c index c87ef25..c622f4c 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