From patchwork Fri Nov 9 01:20:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 995275 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42rj565jyPz9sBk for ; Fri, 9 Nov 2018 12:20:26 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42rj564LHNzF3W3 for ; Fri, 9 Nov 2018 12:20:26 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42rj523bTczF3VL for ; Fri, 9 Nov 2018 12:20:22 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42rj516gmfz9sBk; Fri, 9 Nov 2018 12:20:21 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Fri, 9 Nov 2018 12:20:20 +1100 Message-Id: <20181109012020.3176-1-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 Subject: [Pdbg] [PATCH] device.c: Fix pdbg_target_address X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Commit 936dbdcedb27 ("libpdbg: Rework target addressing") introduced a bug leading to the following assertion failing: pdbg: libpdbg/device.c:634: pdbg_target_address: Assertion `(pos + n) <= p->len' failed. When this function was reworked the index parameter was dropped as every caller set index == 0. Removal should have also resulted in the local pos variable being removed. Instead it was set as if index == 1 resulting in the above violation. Fix the bug and add a test to check pdbg_target_address(). Signed-off-by: Alistair Popple --- libpdbg/device.c | 9 ++++----- src/tests/libpdbg_target_test.c | 10 +++++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index 9557172..f81b1b5 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -626,15 +626,14 @@ uint64_t pdbg_target_address(struct pdbg_target *target, uint64_t *out_size) const struct dt_property *p; u32 na = dt_n_address_cells(target); u32 ns = dt_n_size_cells(target); - u32 pos, n; + u32 n; p = dt_require_property(target, "reg", -1); n = (na + ns) * sizeof(u32); - pos = n; - assert((pos + n) <= p->len); + assert(n <= p->len); if (out_size) - *out_size = dt_get_number(p->prop + pos + na * sizeof(u32), ns); - return dt_get_number(p->prop + pos, na); + *out_size = dt_get_number(p->prop + na * sizeof(u32), ns); + return dt_get_number(p->prop, na); } void pdbg_targets_init(void *fdt) diff --git a/src/tests/libpdbg_target_test.c b/src/tests/libpdbg_target_test.c index 6b64326..eb5e0f4 100644 --- a/src/tests/libpdbg_target_test.c +++ b/src/tests/libpdbg_target_test.c @@ -63,7 +63,7 @@ int main(void) { struct pdbg_target *root, *target, *parent, *parent2; const char *name; - int count; + int count, i; pdbg_targets_init(&_binary_fake_dtb_o_start); @@ -161,7 +161,10 @@ int main(void) assert(!strncmp(name, "pib", 3)); } + i = 0; pdbg_for_each_class_target("core", target) { + uint64_t addr, size; + parent = pdbg_target_parent("fsi", target); assert(parent); @@ -203,6 +206,11 @@ int main(void) name = pdbg_target_dn_name(target); assert(!strncmp(name, "core", 4)); + + addr = pdbg_target_address(target, &size); + assert(size == 0); + assert(addr == 0x10000 + (i / 4)*0x1000 + ((i % 4) + 1)*0x10); + i++; } pdbg_for_each_class_target("thread", target) {