Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] py-inferior.exp: Avoid searching pattern beyond buffer
@ 2011-03-02 15:26 Joel Brobecker
  2011-03-02 18:11 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Joel Brobecker @ 2011-03-02 15:26 UTC (permalink / raw)
  To: gdb-patches; +Cc: Joel Brobecker

The testcase is searching patterns inside a buffer created by
the inferior (a 32,000 character array). At some point, it is
searching successively the same pattern 3 times. It finds the
first one, sets the new search address just right after the find,
then searches again from there, finds the second instance. And
finally does a third search, expecting it to fail because the buffer
has been setup to have only 2 instances of the pattern.

Unfortunately, each search was over the same length, which is 32,000
bytes.  So, starting with the second search, we're already possibly
searching in memory beyond the buffer. We stop the search in time
because we find the second instance.  But in the last search, we
happily search beyond the buffer, because we don't have a match
to stop our search!

We'd have to be pretty unlucky to see a failure, since the search
pattern is pretty specific.  But in fact, I got a failure on LynxOS
(it found a match), and on sparc-solaris as well (we ran into
forbidden memory).

I fixed the problem by making recomputing the length at every search.

gdb/testsuite/ChangeLog:

        * gdb.python/py-inferior.exp: Avoid searching pattern beyond
        end of buffer.

Tested on x86_64-linux.

---
 gdb/testsuite/gdb.python/py-inferior.exp |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp
index c219117..138c0fb 100644
--- a/gdb/testsuite/gdb.python/py-inferior.exp
+++ b/gdb/testsuite/gdb.python/py-inferior.exp
@@ -171,15 +171,15 @@ set CHUNK_SIZE 16000 ;
 gdb_test_no_output "set *(int32_t*) &search_buf\[0*${CHUNK_SIZE}+100\] = 0x12345678"
 gdb_test_no_output "set *(int32_t*) &search_buf\[1*${CHUNK_SIZE}+100\] = 0x12345678"
 gdb_test_no_output "py start_addr = gdb.selected_frame ().read_var ('search_buf')"
-gdb_test_no_output "py length = gdb.selected_frame ().read_var ('search_buf_size')"
+gdb_test_no_output "py end_addr = start_addr + gdb.selected_frame ().read_var ('search_buf_size')"
 gdb_test_no_output "py pattern = pack('${python_pack_char}I', 0x12345678)"
-gdb_test_no_output "py first = gdb.inferiors()\[0\].search_memory (start_addr,length, pattern)"
+gdb_test_no_output "py first = gdb.inferiors()\[0\].search_memory (start_addr,end_addr - start_addr, pattern)"
 gdb_test "py print first" "${one_pattern_found}" "search spanning large range 1st result"
 gdb_test_no_output "py start_addr = first + 1"
-gdb_test_no_output "py second = gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)"
+gdb_test_no_output "py second = gdb.inferiors()\[0\].search_memory (start_addr, end_addr - start_addr, pattern)"
 gdb_test "py print second" "${one_pattern_found}" "search spanning large range 2nd result"
 gdb_test_no_output "py start_addr = second + 1"
-gdb_test_no_output "py third = gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)"
+gdb_test_no_output "py third = gdb.inferiors()\[0\].search_memory (start_addr, end_addr - start_addr, pattern)"
 gdb_test "py print third" "${pattern_not_found}" "search spanning large range 3rd result"
 
 # For native targets, test a pattern straddling a chunk boundary.
@@ -188,6 +188,6 @@ if [isnative] {
     gdb_test_no_output "set *(int32_t*) &search_buf\[${CHUNK_SIZE}-1\] = 0xfdb97531"
     gdb_test_no_output "py pattern = pack('${python_pack_char}I', 0xfdb97531)"
     gdb_test_no_output "py start_addr = gdb.selected_frame ().read_var ('search_buf')"
-    gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
+    gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, end_addr - start_addr, pattern)" \
       "${one_pattern_found}" "find pattern straddling chunk boundary"
 }
-- 
1.7.1


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

* Re: [RFA] py-inferior.exp: Avoid searching pattern beyond buffer
  2011-03-02 15:26 [RFA] py-inferior.exp: Avoid searching pattern beyond buffer Joel Brobecker
@ 2011-03-02 18:11 ` Tom Tromey
  2011-03-03  4:02   ` Joel Brobecker
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2011-03-02 18:11 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

>>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:

Joel>         * gdb.python/py-inferior.exp: Avoid searching pattern beyond
Joel>         end of buffer.

Looks good to me.

Tom


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

* Re: [RFA] py-inferior.exp: Avoid searching pattern beyond buffer
  2011-03-02 18:11 ` Tom Tromey
@ 2011-03-03  4:02   ` Joel Brobecker
  0 siblings, 0 replies; 3+ messages in thread
From: Joel Brobecker @ 2011-03-03  4:02 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

> >>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:
> 
> Joel>         * gdb.python/py-inferior.exp: Avoid searching pattern beyond
> Joel>         end of buffer.
> 
> Looks good to me.

Thanks! Checked in.

-- 
Joel


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

end of thread, other threads:[~2011-03-03  4:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-02 15:26 [RFA] py-inferior.exp: Avoid searching pattern beyond buffer Joel Brobecker
2011-03-02 18:11 ` Tom Tromey
2011-03-03  4:02   ` Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox