analyzer: associate -Wanalyzer-va-list-exhausted with CWE-685
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 16 Jun 2022 21:33:40 +0000 (17:33 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Thu, 16 Jun 2022 21:33:40 +0000 (17:33 -0400)
gcc/analyzer/ChangeLog:
* varargs.cc: Include "diagnostic-metadata.h".
(va_list_exhausted::emit): Associate the warning with
CWE-685 ("Function Call With Incorrect Number of Arguments").

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/stdarg-1.c
(__analyzer_called_by_test_not_enough_args): Verify that
-Wanalyzer-va-list-exhausted is associated with CWE-685.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/analyzer/varargs.cc
gcc/testsuite/gcc.dg/analyzer/stdarg-1.c

index 846a0b1..3baba79 100644 (file)
@@ -50,6 +50,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "sbitmap.h"
 #include "analyzer/diagnostic-manager.h"
 #include "analyzer/exploded-graph.h"
+#include "diagnostic-metadata.h"
 
 #if ENABLE_ANALYZER
 
@@ -903,9 +904,12 @@ public:
   bool emit (rich_location *rich_loc) final override
   {
     auto_diagnostic_group d;
-    bool warned = warning_at (rich_loc, get_controlling_option (),
-                             "%qE has no more arguments (%i consumed)",
-                             m_va_list_tree, get_num_consumed ());
+    diagnostic_metadata m;
+    /* CWE-685: Function Call With Incorrect Number of Arguments.  */
+    m.add_cwe (685);
+    bool warned = warning_meta (rich_loc, m, get_controlling_option (),
+                               "%qE has no more arguments (%i consumed)",
+                               m_va_list_tree, get_num_consumed ());
     return warned;
   }
 
index 295f0ef..41935f7 100644 (file)
@@ -76,7 +76,7 @@ __analyzer_called_by_test_not_enough_args (int placeholder, ...)
   s = __builtin_va_arg (ap, char *);
   __analyzer_eval (s[0] == 'f'); /* { dg-warning "TRUE" } */
 
-  i = __builtin_va_arg (ap, int); /* { dg-warning "'ap' has no more arguments \\(1 consumed\\)" } */
+  i = __builtin_va_arg (ap, int); /* { dg-warning "'ap' has no more arguments \\(1 consumed\\) \\\[CWE-685\\\]" } */
 
   __builtin_va_end (ap);
 }