public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/26901] New: Python array subscript fails with flexible array member without size
@ 2020-11-15  2:47 simark at simark dot ca
  2020-11-15  2:50 ` [Bug gdb/26901] Array " simark at simark dot ca
                   ` (18 more replies)
  0 siblings, 19 replies; 20+ messages in thread
From: simark at simark dot ca @ 2020-11-15  2:47 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26901

            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 <stdlib.h>

struct vectorinox
{
  int size;
  int data[];
};

int main (void)
{
    /* Make a vector of three elements.  */
    struct vectorinox *vector = malloc (sizeof (struct vectorinox) +
sizeof(int) * 3);
    vector->size = 3;
    vector->data[0] = 11;
    vector->data[1] = 22;
    vector->data[2] = 33;

    return 0;
}
---

Trying to access an element of the `data` array in Python yields:

>>> vec = gdb.parse_and_eval('vector')
>>> data = vec['data']
>>> print(data[0])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
gdb.MemoryError: Cannot access memory at address 0x5535555592a0

And with GDB 9.2:

>>> vec = gdb.parse_and_eval('vector')
>>> data = 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 chance
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 bound
isn't a constant, so returns "failure".  However, val_subscript doesn't check
the return value, and uses the uninitialized values of low and high bounds, and
it goes downhill from there.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2021-11-25 13:58 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-15  2:47 [Bug gdb/26901] New: Python array subscript fails with flexible array member without size simark at simark dot ca
2020-11-15  2:50 ` [Bug gdb/26901] Array " simark at simark dot ca
2020-11-15  2:50 ` simark at simark dot ca
2020-11-16 18:21 ` simark at simark dot ca
2020-12-03 19:01 ` simark at simark dot ca
2020-12-09 18:53 ` cvs-commit at gcc dot gnu.org
2020-12-09 21:34 ` cvs-commit at gcc dot gnu.org
2020-12-09 22:11 ` simark at simark dot ca
2021-06-27 18:00 ` ahmedsayeed1982 at yahoo dot com
2021-08-10 12:45 ` ucelsanicin at yahoo dot com
2021-09-02 11:06 ` donipah907 at mtlcz dot com
2021-09-02 11:16 ` mark at klomp dot org
2021-09-06  9:09 ` focixujo at livinginsurance dot co.uk
2021-09-10 19:39 ` mehmetgelisin at aol dot com
2021-09-22 10:19 ` diheto5497 at secbuf dot com
2021-10-09 11:00 ` gulsenenginar at aol dot com
2021-10-17 19:49 ` vmireskazki at gmail dot com
2021-10-19  7:15 ` progonsaytu at gmail dot com
2021-10-24 10:02 ` glassmtech at ukr dot net
2021-11-25 13:58 ` mdxconcepts0008 at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).