From: Vsevolod Stakhov Date: Wed, 11 Nov 2015 17:10:16 +0000 (+0000) Subject: Improve format string parsing. X-Git-Tag: 1.1.0~583 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=613265222dc98a7dfdffa4a84966606f4c3e8445;p=thirdparty%2Frspamd.git Improve format string parsing. --- diff --git a/clang-plugin/printf_check.cc b/clang-plugin/printf_check.cc index 6873cc398e..c2144127b7 100644 --- a/clang-plugin/printf_check.cc +++ b/clang-plugin/printf_check.cc @@ -29,6 +29,7 @@ #include "clang/AST/ASTConsumer.h" #include "clang/AST/RecursiveASTVisitor.h" #include +#include #include #include #include @@ -137,6 +138,7 @@ namespace rspamd { class PrintfCheckVisitor::impl { std::unordered_map printf_functions; + std::unordered_set format_specs; ASTContext *pcontext; CompilerInstance *ci; @@ -278,7 +280,13 @@ namespace rspamd { } break; case read_arg: - if (!isalpha (c)) { + auto found = format_specs.find (c); + if (found != format_specs.end () || !isalpha (c)) { + + if (isalpha (c)) { + flags.push_back (c); + } + auto handler = parseFlags (flags, e); if (handler) { @@ -333,6 +341,11 @@ namespace rspamd { {"rspamd_snprintf", 2}, {"rspamd_fprintf", 1} }; + + format_specs = { + 's', 'd', 'l', 'L', 'v', 'V', 'f', 'F', 'g', 'G', + 'T', 'z', 'D', 'c', 'p', 'P', 'e' + }; }; bool VisitCallExpr (CallExpr *E)