diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2014-04-22 10:59:13 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2014-04-22 10:59:13 +0000 |
commit | 93043620bc63102f3316bfbec4aab33d06df334b (patch) | |
tree | 8f539a202bc6bdb17f37dbb365198ed4e6e1ae26 /clang/lib/AST/CommentSema.cpp | |
parent | 6e647c13e451dc57f01e96d1d1dafc8c9b406959 (diff) | |
download | bcm5719-llvm-93043620bc63102f3316bfbec4aab33d06df334b.tar.gz bcm5719-llvm-93043620bc63102f3316bfbec4aab33d06df334b.zip |
Comment parsing: in the generated XML file, mark HTML that is safe to pass
through to the output even if the input comment comes from an untrusted source
Attribute filtering is currently based on a blacklist, which right now includes
all event handler attributes (they contain JavaScipt code). It should be
switched to a whitelist, but going over all of the HTML5 spec requires a
significant amount of time.
llvm-svn: 206882
Diffstat (limited to 'clang/lib/AST/CommentSema.cpp')
-rw-r--r-- | clang/lib/AST/CommentSema.cpp | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp index e51f8781c1b..5a0bf37739c 100644 --- a/clang/lib/AST/CommentSema.cpp +++ b/clang/lib/AST/CommentSema.cpp @@ -467,6 +467,11 @@ void Sema::actOnHTMLStartTagFinish( SourceLocation GreaterLoc, bool IsSelfClosing) { Tag->setAttrs(Attrs); + for (const auto &Attr : Attrs) { + if (!isHTMLAttributeSafeToPassThrough(Attr.Name)) + Tag->setUnsafeToPassThrough(); + } + Tag->setGreaterLoc(GreaterLoc); if (IsSelfClosing) Tag->setSelfClosing(); @@ -482,6 +487,7 @@ HTMLEndTagComment *Sema::actOnHTMLEndTag(SourceLocation LocBegin, if (isHTMLEndTagForbidden(TagName)) { Diag(HET->getLocation(), diag::warn_doc_html_end_forbidden) << TagName << HET->getSourceRange(); + HET->setUnsafeToPassThrough(); return HET; } @@ -497,14 +503,19 @@ HTMLEndTagComment *Sema::actOnHTMLEndTag(SourceLocation LocBegin, if (!FoundOpen) { Diag(HET->getLocation(), diag::warn_doc_html_end_unbalanced) << HET->getSourceRange(); + HET->setUnsafeToPassThrough(); return HET; } while (!HTMLOpenTags.empty()) { - const HTMLStartTagComment *HST = HTMLOpenTags.pop_back_val(); + HTMLStartTagComment *HST = HTMLOpenTags.pop_back_val(); StringRef LastNotClosedTagName = HST->getTagName(); - if (LastNotClosedTagName == TagName) + if (LastNotClosedTagName == TagName) { + // If the start tag is unsafe, end tag is unsafe as well. + if (!HST->isSafeToPassThrough()) + HET->setUnsafeToPassThrough(); break; + } if (isHTMLEndTagOptional(LastNotClosedTagName)) continue; @@ -518,16 +529,18 @@ HTMLEndTagComment *Sema::actOnHTMLEndTag(SourceLocation LocBegin, HET->getLocation(), &CloseLineInvalid); - if (OpenLineInvalid || CloseLineInvalid || OpenLine == CloseLine) + if (OpenLineInvalid || CloseLineInvalid || OpenLine == CloseLine) { Diag(HST->getLocation(), diag::warn_doc_html_start_end_mismatch) << HST->getTagName() << HET->getTagName() << HST->getSourceRange() << HET->getSourceRange(); - else { + HST->setUnsafeToPassThrough(); + } else { Diag(HST->getLocation(), diag::warn_doc_html_start_end_mismatch) << HST->getTagName() << HET->getTagName() << HST->getSourceRange(); Diag(HET->getLocation(), diag::note_doc_html_end_tag) << HET->getSourceRange(); + HST->setUnsafeToPassThrough(); } } @@ -538,6 +551,18 @@ FullComment *Sema::actOnFullComment( ArrayRef<BlockContentComment *> Blocks) { FullComment *FC = new (Allocator) FullComment(Blocks, ThisDeclInfo); resolveParamCommandIndexes(FC); + + // Complain about HTML tags that are not closed. + while (!HTMLOpenTags.empty()) { + HTMLStartTagComment *HST = HTMLOpenTags.pop_back_val(); + if (isHTMLEndTagOptional(HST->getTagName())) + continue; + + Diag(HST->getLocation(), diag::warn_doc_html_missing_end_tag) + << HST->getTagName() << HST->getSourceRange(); + HST->setUnsafeToPassThrough(); + } + return FC; } |