]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
A fix for bug 186796: suppression symbol names were being truncated if they
authorNicholas Nethercote <njn@valgrind.org>
Fri, 24 Jul 2009 07:38:29 +0000 (07:38 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Fri, 24 Jul 2009 07:38:29 +0000 (07:38 +0000)
were longer than 200 chars.  Now dynamic memory is used and so they can be
arbitrarily long in theory, although in practice it bombs out at 100,000 for
sanity purposes.  This required adjusting the core/tool interface for
read_extra_suppression_info().

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10581

16 files changed:
coregrind/m_errormgr.c
coregrind/m_tooliface.c
coregrind/pub_core_tooliface.h
exp-ptrcheck/pc_common.c
exp-ptrcheck/pc_common.h
helgrind/hg_errors.c
helgrind/hg_errors.h
include/pub_tool_errormgr.h
include/pub_tool_tooliface.h
memcheck/mc_errors.c
memcheck/mc_include.h
memcheck/tests/Makefile.am
memcheck/tests/long-supps.c [new file with mode: 0644]
memcheck/tests/long-supps.stderr.exp [new file with mode: 0644]
memcheck/tests/long-supps.supp [new file with mode: 0644]
memcheck/tests/long-supps.vgtest [new file with mode: 0644]

index 64ae47aa93fd91f842eb5136c55ce64ea2365000..cf0b8dff14e6d9f803ed3aac1d78a6f08c52b5f3 100644 (file)
@@ -964,14 +964,12 @@ static Int get_char ( Int fd, Char* out_buf )
    return 1;
 }
 
-
-/* Get a non-blank, non-comment line of at most nBuf chars from fd.
-   Skips leading spaces on the line. Return True if EOF was hit instead. 
-*/
-Bool VG_(get_line) ( Int fd, Char* buf, Int nBuf )
+Bool VG_(get_line) ( Int fd, Char** bufpp, SizeT* nBufp )
 {
-   Char ch;
-   Int  n, i;
+   Char* buf  = *bufpp;
+   SizeT nBuf = *nBufp;
+   Char  ch;
+   Int   n, i;
    while (True) {
       /* First, read until a non-blank char appears. */
       while (True) {
@@ -987,7 +985,14 @@ Bool VG_(get_line) ( Int fd, Char* buf, Int nBuf )
          n = get_char(fd, &ch);
          if (n <= 0) return False; /* the next call will return True */
          if (ch == '\n') break;
-         if (i > 0 && i == nBuf-1) i--;
+         if (i > 0 && i == nBuf-1) {
+            *nBufp = nBuf = nBuf * 2;
+            #define RIDICULOUS   100000
+            vg_assert2(nBuf < RIDICULOUS,  // Just a sanity check, really.
+               "VG_(get_line): line longer than %d chars, aborting\n",
+               RIDICULOUS);
+            *bufpp = buf = VG_(realloc)("errormgr.get_line.1", buf, nBuf);
+         }
          buf[i++] = ch; buf[i] = 0;
       }
       while (i > 1 && VG_(isspace)(buf[i-1])) { 
@@ -1053,11 +1058,11 @@ static Bool tool_name_present(Char *name, Char *names)
 */
 static void load_one_suppressions_file ( Char* filename )
 {
-#  define N_BUF 200
    SysRes sres;
    Int    fd, i, j, lineno = 0;
    Bool   eof;
-   Char   buf[N_BUF+1];
+   SizeT  nBuf = 200;
+   Char*  buf = VG_(malloc)("errormgr.losf.1", nBuf);
    Char*  tool_names;
    Char*  supp_name;
    Char*  err_str = NULL;
@@ -1098,20 +1103,20 @@ static void load_one_suppressions_file ( Char* filename )
 
       supp->string = supp->extra = NULL;
 
-      eof = VG_(get_line) ( fd, buf, N_BUF );
+      eof = VG_(get_line) ( fd, &buf, &nBuf );
       lineno++;
       if (eof) break;
 
       if (!VG_STREQ(buf, "{")) BOMB("expected '{' or end-of-file");
       
-      eof = VG_(get_line) ( fd, buf, N_BUF );
+      eof = VG_(get_line) ( fd, &buf, &nBuf );
       lineno++;
 
       if (eof || VG_STREQ(buf, "}")) BOMB("unexpected '}'");
 
       supp->sname = VG_(arena_strdup)(VG_AR_CORE, "errormgr.losf.2", buf);
 
-      eof = VG_(get_line) ( fd, buf, N_BUF );
+      eof = VG_(get_line) ( fd, &buf, &nBuf );
       lineno++;
 
       if (eof) BOMB("unexpected end-of-file");
@@ -1150,7 +1155,7 @@ static void load_one_suppressions_file ( Char* filename )
       else {
          // Ignore rest of suppression
          while (True) {
-            eof = VG_(get_line) ( fd, buf, N_BUF );
+            eof = VG_(get_line) ( fd, &buf, &nBuf );
             lineno++;
             if (eof) BOMB("unexpected end-of-file");
             if (VG_STREQ(buf, "}"))
@@ -1161,7 +1166,7 @@ static void load_one_suppressions_file ( Char* filename )
 
       if (VG_(needs).tool_errors && 
           !VG_TDICT_CALL(tool_read_extra_suppression_info,
-                         fd, buf, N_BUF, supp))
+                         fd, &buf, &nBuf, supp))
       {
          BOMB("bad or missing extra suppression info");
       }
@@ -1169,7 +1174,7 @@ static void load_one_suppressions_file ( Char* filename )
       /* the main frame-descriptor reading loop */
       i = 0;
       while (True) {
-         eof = VG_(get_line) ( fd, buf, N_BUF );
+         eof = VG_(get_line) ( fd, &buf, &nBuf );
          lineno++;
          if (eof)
             BOMB("unexpected end-of-file");
@@ -1196,7 +1201,7 @@ static void load_one_suppressions_file ( Char* filename )
       // lines and grab the '}'.
       if (!VG_STREQ(buf, "}")) {
          do {
-            eof = VG_(get_line) ( fd, buf, N_BUF );
+            eof = VG_(get_line) ( fd, &buf, &nBuf );
             lineno++;
          } while (!eof && !VG_STREQ(buf, "}"));
       }
@@ -1227,6 +1232,7 @@ static void load_one_suppressions_file ( Char* filename )
       supp->next = suppressions;
       suppressions = supp;
    }
+   VG_(free)(buf);
    VG_(close)(fd);
    return;
 
@@ -1242,7 +1248,6 @@ static void load_one_suppressions_file ( Char* filename )
    VG_(exit)(1);
 
 #  undef BOMB
-#  undef N_BUF   
 }
 
 
index e6d1652e71b6ea2d621f1554da410dc535b22879..6f76d5978882b746fb48593fc1339c07871a887e 100644 (file)
@@ -230,7 +230,7 @@ void VG_(needs_tool_errors)(
    Bool show_TIDs,
    UInt (*update)     (Error*),
    Bool (*recog)      (Char*, Supp*),
-   Bool (*read_extra) (Int, Char*, Int, Supp*),
+   Bool (*read_extra) (Int, Char**, SizeT*, Supp*),
    Bool (*matches)    (Error*, Supp*),
    Char* (*name)      (Error*),
    void (*print_extra)(Error*)
index f9a8005405bb9c655b251fb054f9dc4506f69302..9e928cb4916538584be6f5fd887f161bf5c48d13 100644 (file)
@@ -122,7 +122,7 @@ typedef struct {
    Bool  tool_show_ThreadIDs_for_errors;
    UInt  (*tool_update_extra)                (Error*);
    Bool  (*tool_recognised_suppression)      (Char*, Supp*);
-   Bool  (*tool_read_extra_suppression_info) (Int, Char*, Int, Supp*);
+   Bool  (*tool_read_extra_suppression_info) (Int, Char**, SizeT*, Supp*);
    Bool  (*tool_error_matches_suppression)   (Error*, Supp*);
    Char* (*tool_get_error_name)              (Error*);
    void  (*tool_print_extra_suppression_info)(Error*);
index 3d75748d3c125c21523d9d29886d16586d3c64b2..365ffe95d162eb2ab770cda528984d67cc9e634f 100644 (file)
@@ -736,14 +736,14 @@ Bool pc_is_recognised_suppression ( Char* name, Supp *su )
    return True;
 }
 
-Bool pc_read_extra_suppression_info ( Int fd, Char* buf
-                                      Int nBuf, Supp* su )
+Bool pc_read_extra_suppression_info ( Int fd, Char** bufpp
+                                      SizeT* nBufp, Supp* su )
 {
    Bool eof;
    if (VG_(get_supp_kind)(su) == XS_SysParam) {
-      eof = VG_(get_line) ( fd, buf, nBuf );
+      eof = VG_(get_line) ( fd, bufpp, nBufp );
       if (eof) return False;
-      VG_(set_supp_string)(su, VG_(strdup)("pc.common.presi.1", buf));
+      VG_(set_supp_string)(su, VG_(strdup)("pc.common.presi.1", *bufpp));
    }
    return True;
 }
index 9c440d1672de335ec2c8346b802c9e1a6e5ed667..1e2549af4c193ef260910c513bcebbc86bab29a5 100644 (file)
@@ -52,8 +52,8 @@ void pc_before_pp_Error    ( Error* err );
 void pc_pp_Error           ( Error* err );
 UInt pc_update_Error_extra ( Error* err );
 Bool pc_is_recognised_suppression ( Char* name, Supp *su );
-Bool pc_read_extra_suppression_info ( Int fd, Char* buf
-                                      Int nBuf, Supp* su );
+Bool pc_read_extra_suppression_info ( Int fd, Char** bufpp
+                                      SizeT* nBufp, Supp* su );
 Bool pc_error_matches_suppression (Error* err, Supp* su);
 Char* pc_get_error_name ( Error* err );
 void pc_print_extra_suppression_info ( Error* err );
index 1d1acc2244786db7a77d97403e8a418956d83364..8a7ebe111776399777ad2e459955bbb1bdd31ed2 100644 (file)
@@ -1006,7 +1006,7 @@ Bool HG_(recognised_suppression) ( Char* name, Supp *su )
 #  undef TRY
 }
 
-Bool HG_(read_extra_suppression_info) ( Int fd, Char* buf, Int nBuf,
+Bool HG_(read_extra_suppression_info) ( Int fd, Char** bufpp, SizeT* nBufp,
                                         Supp* su )
 {
    /* do nothing -- no extra suppression info present.  Return True to
index 9bb6502c09202a6c5eed488247ae42f8036235ca..9760b92790df1aa449db1eaaa1e12eb672723c10 100644 (file)
@@ -40,7 +40,7 @@ void  HG_(before_pp_Error) ( Error* err );
 void  HG_(pp_Error)        ( Error* err );
 UInt  HG_(update_extra)    ( Error* err );
 Bool  HG_(recognised_suppression) ( Char* name, Supp *su );
-Bool  HG_(read_extra_suppression_info) ( Int fd, Char* buf, Int nBuf,
+Bool  HG_(read_extra_suppression_info) ( Int fd, Char** bufpp, SizeT* nBufp,
                                          Supp* su );
 Bool  HG_(error_matches_suppression) ( Error* err, Supp* su );
 Char* HG_(get_error_name) ( Error* err );
index 0d22c1bbadcb749e98954f9435634951459d0855..8369cf12997c74e877f633424d64d5b5da01e4eb 100644 (file)
@@ -87,10 +87,13 @@ extern Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind,
                                 ExeContext* where, Bool print_error,
                                 Bool allow_GDB_attach, Bool count_error );
 
-/* Gets a non-blank, non-comment line of at most nBuf chars from fd.
-   Skips leading spaces on the line.  Returns True if EOF was hit instead.
-   Useful for reading in extra tool-specific suppression lines.  */
-extern Bool VG_(get_line) ( Int fd, Char* buf, Int nBuf );
+/* Gets a non-blank, non-comment line from fd.  bufpp is a pointer to a
+   pointer to a buffer that must be allocated with VG_(malloc);  nBufp is a
+   pointer to size_t holding its size;  if the buffer is too small for the
+   line, it will be realloc'd until big enough (updating *bufpp and *nBufp in
+   the process).  (It will bomb out if the size gets ridiculous).  Skips
+   leading spaces on the line.  Returns True if EOF was hit instead.  */
+extern Bool VG_(get_line) ( Int fd, Char** bufpp, SizeT* nBufp );
 
 
 /* ------------------------------------------------------------------ */
index bce2b227f8b19ca2e9e0bc0cacef7f5e29ff26f7..1a36f158aac92843cd2a011c85b73669c4be4c7f 100644 (file)
@@ -316,8 +316,10 @@ extern void VG_(needs_tool_errors) (
    // Read any extra info for this suppression kind.  Most likely for filling
    // in the `extra' and `string' parts (with VG_(set_supp_{extra, string})())
    // of a suppression if necessary.  Should return False if a syntax error
-   // occurred, True otherwise.
-   Bool (*read_extra_suppression_info)(Int fd, Char* buf, Int nBuf, Supp* su),
+   // occurred, True otherwise.  bufpp and nBufp are the same as for
+   // VG_(get_line).
+   Bool (*read_extra_suppression_info)(Int fd, Char** bufpp, SizeT* nBufp,
+                                       Supp* su),
 
    // This should just check the kinds match and maybe some stuff in the
    // `string' and `extra' field if appropriate (using VG_(get_supp_*)() to
index 4ccaa608ee0d5c5fb0ee3a42619aecf421d90a93..4e88f7988920c97df4d2e873ad643944fb217943 100644 (file)
@@ -1384,15 +1384,15 @@ Bool MC_(is_recognised_suppression) ( Char* name, Supp* su )
    return True;
 }
 
-Bool MC_(read_extra_suppression_info) ( Int fd, Char* buf,
-                                        Int nBuf, Supp *su )
+Bool MC_(read_extra_suppression_info) ( Int fd, Char** bufpp,
+                                        SizeT* nBufp, Supp *su )
 {
    Bool eof;
 
    if (VG_(get_supp_kind)(su) == ParamSupp) {
-      eof = VG_(get_line) ( fd, buf, nBuf );
+      eof = VG_(get_line) ( fd, bufpp, nBufp );
       if (eof) return False;
-      VG_(set_supp_string)(su, VG_(strdup)("mc.resi.1", buf));
+      VG_(set_supp_string)(su, VG_(strdup)("mc.resi.1", *bufpp));
    }
    return True;
 }
index fc7abf2085651ca7414aabfa12f441466db52e45..f81b379073e2f437450ce64d4b2827ce1af07148 100644 (file)
@@ -312,8 +312,8 @@ UInt MC_(update_Error_extra) ( Error* err );
 
 Bool MC_(is_recognised_suppression) ( Char* name, Supp* su );
 
-Bool MC_(read_extra_suppression_info) ( Int fd, Char* buf,
-                                        Int nBuf, Supp *su );
+Bool MC_(read_extra_suppression_info) ( Int fd, Char** buf,
+                                        SizeT* nBuf, Supp *su );
 
 Bool MC_(error_matches_suppression) ( Error* err, Supp* su );
 
index 09fdb2a1d83c39badec5208f32123cb9b0dc4e4b..3d16a9573dafb91b2bb5b6e260dffef9ff6f1fb8 100644 (file)
@@ -83,6 +83,7 @@ EXTRA_DIST = \
        linux-syscalls-2007 linux-syscalls-2007.stderr.exp \
        long_namespace_xml.vgtest long_namespace_xml.stdout.exp \
        long_namespace_xml.stderr.exp \
+       long-supps.vgtest long-supps.stderr.exp long-supps.supp \
        lsframe1.vgtest lsframe1.stdout.exp lsframe1.stderr.exp \
        lsframe2.vgtest lsframe2.stdout.exp lsframe2.stderr.exp \
        mallinfo.stderr.exp mallinfo.vgtest \
@@ -202,11 +203,15 @@ check_PROGRAMS = \
        fprw fwrite inits inline \
        leak-0 \
        leak-cases \
-       leak-cycle leak-pool leak-tree \
+       leak-cycle \
+       leak-pool \
+       leak-tree \
        linux-syslog-syscall \
        linux-syscalls-2007 \
        long_namespace_xml \
-       lsframe1 lsframe2 \
+       long-supps \
+       lsframe1 \
+       lsframe2 \
        mallinfo \
        malloc_free_fill \
        malloc_usable malloc1 malloc2 malloc3 manuel1 manuel2 manuel3 \
diff --git a/memcheck/tests/long-supps.c b/memcheck/tests/long-supps.c
new file mode 100644 (file)
index 0000000..78377e3
--- /dev/null
@@ -0,0 +1,20 @@
+// Bug 186796:  function names of over 200 chars in suppressions were being
+// truncated and so not matching.  This 200 char limit is easily overcome with
+// C++ templates.  It now is assigned dynamically.
+
+#include <stdlib.h>
+
+#define F1000 \
+f1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
+
+void F1000(void)
+{
+   int* x = malloc(sizeof(int));
+   x[1] = 1;
+}
+
+int main(void)
+{
+   F1000();
+   return 0;
+}
diff --git a/memcheck/tests/long-supps.stderr.exp b/memcheck/tests/long-supps.stderr.exp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/memcheck/tests/long-supps.supp b/memcheck/tests/long-supps.supp
new file mode 100644 (file)
index 0000000..3eabaf6
--- /dev/null
@@ -0,0 +1,7 @@
+{
+   <insert a suppression name here>
+   Memcheck:Addr4
+   fun:f1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
+   fun:main
+}
+
diff --git a/memcheck/tests/long-supps.vgtest b/memcheck/tests/long-supps.vgtest
new file mode 100644 (file)
index 0000000..8750ac7
--- /dev/null
@@ -0,0 +1,2 @@
+prog: long-supps
+vgopts: --suppressions=long-supps.supp -q