gdb/
authorJan Kratochvil <jan.kratochvil@redhat.com>
Fri, 6 Jul 2012 15:51:40 +0000 (15:51 +0000)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Fri, 6 Jul 2012 15:51:40 +0000 (15:51 +0000)
PR 14321
* findcmd.c (parse_find_args): New variable pattern_buf_size_need.
Increase buffer sizes to 2x we need, not just 2x of the previous size.

gdb/testsuite/
PR 14321
* gdb.base/find.exp
(find int64_search_buf, +64/8*100, int64_search_buf): New test.

gdb/ChangeLog
gdb/findcmd.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/find.exp

index 16e795c8883062834e1a96ee8374c6c687a021f6..5c434a0632ddca86095689b75eda7705f949cfea 100644 (file)
@@ -1,3 +1,9 @@
+2012-07-06  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       PR 14321
+       * findcmd.c (parse_find_args): New variable pattern_buf_size_need.
+       Increase buffer sizes to 2x we need, not just 2x of the previous size.
+
 2012-07-06  Tom Tromey  <tromey@redhat.com>
 
        * c-exp.y (DOTDOTDOT): New token.
index 3fce2695919c096297bcb5d6df77f7c8f18bc33d..68184aa27e981cc0e675fa33e560ea0127071eb9 100644 (file)
@@ -170,6 +170,7 @@ parse_find_args (char *args, ULONGEST *max_countp,
     {
       LONGEST x;
       int val_bytes;
+      ULONGEST pattern_buf_size_need;
 
       while (isspace (*s))
        ++s;
@@ -179,12 +180,13 @@ parse_find_args (char *args, ULONGEST *max_countp,
 
       /* Keep it simple and assume size == 'g' when watching for when we
         need to grow the pattern buf.  */
-      if ((pattern_buf_end - pattern_buf + max (val_bytes, sizeof (int64_t)))
-         > pattern_buf_size)
+      pattern_buf_size_need = (pattern_buf_end - pattern_buf
+                              + max (val_bytes, sizeof (int64_t)));
+      if (pattern_buf_size_need > pattern_buf_size)
        {
          size_t current_offset = pattern_buf_end - pattern_buf;
 
-         pattern_buf_size *= 2;
+         pattern_buf_size = pattern_buf_size_need * 2;
          pattern_buf = xrealloc (pattern_buf, pattern_buf_size);
          pattern_buf_end = pattern_buf + current_offset;
        }
index fdc921d709630120111357b9f8078dc88b15f962..4301b03286804098e8ccafc60340be214c8e3407 100644 (file)
@@ -1,3 +1,9 @@
+2012-07-06  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       PR 14321
+       * gdb.base/find.exp
+       (find int64_search_buf, +64/8*100, int64_search_buf): New test.
+
 2012-07-06  Tom Tromey  <tromey@redhat.com>
 
        * gdb.base/whatis.exp: Add test.
index ad54d65b888cb5287a135ef2c65a6f233c10f52e..5e41d9786df41257e409abfb0dd6a69fe8c0a513 100644 (file)
@@ -182,3 +182,6 @@ if [isnative] {
     "${hex_number}${one_pattern_found}" \
     "find pattern straddling chunk boundary"
 }
+
+# Check GDB buffer overflow.
+gdb_test "find int64_search_buf, +64/8*100, int64_search_buf" " <int64_search_buf>\r\n1 pattern found\\."