From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3B2673851C0C; Sun, 15 Nov 2020 02:47:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B2673851C0C From: "simark at simark dot ca" To: gdb-prs@sourceware.org Subject: [Bug gdb/26901] New: Python array subscript fails with flexible array member without size Date: Sun, 15 Nov 2020 02:47:00 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: gdb X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: simark at simark dot ca X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gdb-prs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-prs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Nov 2020 02:47:00 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D26901 Bug ID: 26901 Summary: Python array subscript fails with flexible array member without size Product: gdb Version: HEAD Status: NEW Severity: normal Priority: P2 Component: gdb Assignee: unassigned at sourceware dot org Reporter: simark at simark dot ca Target Milestone: --- Consider this program: --- #include struct vectorinox { int size; int data[]; }; int main (void) { /* Make a vector of three elements. */ struct vectorinox *vector =3D malloc (sizeof (struct vectorinox) + sizeof(int) * 3); vector->size =3D 3; vector->data[0] =3D 11; vector->data[1] =3D 22; vector->data[2] =3D 33; return 0; } --- Trying to access an element of the `data` array in Python yields: >>> vec =3D gdb.parse_and_eval('vector') >>> data =3D vec['data'] >>> print(data[0]) Traceback (most recent call last): File "", line 1, in gdb.MemoryError: Cannot access memory at address 0x5535555592a0 And with GDB 9.2: >>> vec =3D gdb.parse_and_eval('vector') >>> data =3D vec['data'] >>> print(data[0]) 11 This failure was introduced by commit 7c6f27129631 ("gdb: make get_discrete_bounds check for non-constant range bounds"). Unfortunately, = this commit doesn't build, but it's trivial to fix if you want to try it: just remove the parenthesis after `kind` that it introduces. val_subscript passes the array's index type (of type code TYPE_CODE_RANGE) = to get_discrete_bounds. The index type has the low bound set to constant 0 and the high bound unknown. Before the commit, get_discrete_bounds would return "success" and set the low and high bound to 0. Although it's a bit by chan= ce that it returned 0 for the high bound, since the bound was "unknown". It doesn't really matter in that case because the high bound doesn't get used = by the caller. After the commit, the new check in get_discrete_bounds sees that the high b= ound isn't a constant, so returns "failure". However, val_subscript doesn't che= ck the return value, and uses the uninitialized values of low and high bounds,= and it goes downhill from there. --=20 You are receiving this mail because: You are on the CC list for the bug.=