From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13092 invoked by alias); 2 Mar 2011 15:26:55 -0000 Received: (qmail 13083 invoked by uid 22791); 2 Mar 2011 15:26:54 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 02 Mar 2011 15:26:49 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id AB1512BAD90; Wed, 2 Mar 2011 10:26:47 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Som28XXXAlPf; Wed, 2 Mar 2011 10:26:47 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 270432BAD34; Wed, 2 Mar 2011 10:26:47 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 9352E1459AD; Wed, 2 Mar 2011 19:26:31 +0400 (RET) From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Joel Brobecker Subject: [RFA] py-inferior.exp: Avoid searching pattern beyond buffer Date: Wed, 02 Mar 2011 15:26:00 -0000 Message-Id: <1299079586-23077-1-git-send-email-brobecker@adacore.com> Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-03/txt/msg00104.txt.bz2 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