Closed Bug 1604307 Opened 4 months ago Closed 4 months ago

null pointer passed as argument 1, which is declared to never be null in parser/html/nsHtml5String.cpp:71

Categories

(Core :: DOM: HTML Parser, defect)

defect
Not set

Tracking

()

RESOLVED FIXED
mozilla73
Tracking Status
firefox73 --- fixed

People

(Reporter: tsmith, Assigned: hsivonen)

References

(Blocks 2 open bugs)

Details

(Keywords: testcase)

Attachments

(2 files)

Attached file testcase.html

This is triggered with an UBSan build. To enable this check add the following to your mozconfig:

ac_add_options --enable-address-sanitizer
ac_add_options --enable-undefined-sanitizer="nonnull-attribute"
ac_add_options --disable-jemalloc
src/parser/html/nsHtml5String.cpp:71:18: runtime error: null pointer passed as argument 1, which is declared to never be null
/usr/include/string.h:64:33: note: nonnull attribute specified here
    #0 0x7f7f2c10266a in nsHtml5String::Equals(nsHtml5String) const src/parser/html/nsHtml5String.cpp:71:11
    #1 0x7f7f2c0cd26d in nsHtml5HtmlAttributes::equalsAnother(nsHtml5HtmlAttributes*) src/parser/html/nsHtml5HtmlAttributes.cpp:185:31
    #2 0x7f7f2c11c9c7 in nsHtml5TreeBuilder::maybeForgetEarlierDuplicateFormattingElement(nsAtom*, nsHtml5HtmlAttributes*) src/parser/html/nsHtml5TreeBuilder.cpp:3876:49
    #3 0x7f7f2c10ba81 in nsHtml5TreeBuilder::startTag(nsHtml5ElementName*, nsHtml5HtmlAttributes*, bool) src/parser/html/nsHtml5TreeBuilder.cpp:1275:15
    #4 0x7f7f2c1069a7 in nsHtml5Tokenizer::emitCurrentTagToken(bool, int) src/parser/html/nsHtml5Tokenizer.cpp:342:21
    #5 0x7f7f2c1448c7 in int nsHtml5Tokenizer::stateLoop<nsHtml5SilentPolicy>(int, char16_t, int, char16_t*, bool, int, int) src/parser/html/nsHtml5Tokenizer.cpp:964:32
    #6 0x7f7f2c0fd2ad in nsHtml5Tokenizer::tokenizeBuffer(nsHtml5UTF16Buffer*) src/parser/html/nsHtml5Tokenizer.cpp:443:11
    #7 0x7f7f2c104073 in nsHtml5StringParser::Tokenize(nsTSubstring<char16_t> const&, mozilla::dom::Document*, bool) src/parser/html/nsHtml5StringParser.cpp:101:33
    #8 0x7f7f2d3a9781 in nsContentUtils::ParseFragmentHTML(nsTSubstring<char16_t> const&, nsIContent*, nsAtom*, int, bool, bool) src/dom/base/nsContentUtils.cpp:4719:38
    #9 0x7f7f31a8eee6 in mozilla::HTMLEditor::ParseFragment(nsTSubstring<char16_t> const&, nsAtom*, mozilla::dom::Document*, mozilla::dom::DocumentFragment**, bool) src/editor/libeditor/HTMLEditorDataTransfer.cpp:2657:17
    #10 0x7f7f31a80e7a in mozilla::HTMLEditor::CreateDOMFragmentFromPaste(nsTSubstring<char16_t> const&, nsTSubstring<char16_t> const&, nsTSubstring<char16_t> const&, nsCOMPtr<nsINode>*, nsCOMPtr<nsINode>*, nsCOMPtr<nsINode>*, int*, int*, bool) src/editor/libeditor/HTMLEditorDataTransfer.cpp:2593:8
    #11 0x7f7f31a7ec3d in mozilla::HTMLEditor::DoInsertHTMLWithContext(nsTSubstring<char16_t> const&, nsTSubstring<char16_t> const&, nsTSubstring<char16_t> const&, nsTSubstring<char16_t> const&, mozilla::dom::Document*, mozilla::EditorDOMPointBase<nsCOMPtr<nsINode>, nsCOMPtr<nsIContent> > const&, bool, bool, bool) src/editor/libeditor/HTMLEditorDataTransfer.cpp:219:17
    #12 0x7f7f31a7da52 in mozilla::HTMLEditor::InsertHTMLAsAction(nsTSubstring<char16_t> const&, nsIPrincipal*) src/editor/libeditor/HTMLEditorDataTransfer.cpp:183:17
    #13 0x7f7f2d60e3b7 in mozilla::dom::Document::ExecCommand(nsTSubstring<char16_t> const&, bool, nsTSubstring<char16_t> const&, nsIPrincipal&, mozilla::ErrorResult&) src/dom/base/Document.cpp:4671:26
    #14 0x7f7f2ec1cf8d in mozilla::dom::Document_Binding::execCommand(JSContext*, JS::Handle<JSObject*>, void*, JSJitMethodCallArgs const&) src/objdir-ff-ubsan/dom/bindings/DocumentBinding.cpp:3429:36
    #15 0x7f7f2f0c64b1 in bool mozilla::dom::binding_detail::GenericMethod<mozilla::dom::binding_detail::NormalThisPolicy, mozilla::dom::binding_detail::ThrowExceptions>(JSContext*, unsigned int, JS::Value*) src/dom/bindings/BindingUtils.cpp:3151:13
    #16 0x7f7f35c96630 in CallJSNative(JSContext*, bool (*)(JSContext*, unsigned int, JS::Value*), js::CallReason, JS::CallArgs const&) src/js/src/vm/Interpreter.cpp:457:13
    #17 0x7f7f35c96630 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) src/js/src/vm/Interpreter.cpp:549:12
    #18 0x7f7f35c9763a in InternalCall(JSContext*, js::AnyInvokeArgs const&, js::CallReason) src/js/src/vm/Interpreter.cpp:618:10
    #19 0x7f7f35c80d76 in Interpret(JSContext*, js::RunState&) src/js/src/vm/Interpreter.cpp:3116:16
    #20 0x7f7f35c63e15 in js::RunScript(JSContext*, js::RunState&) src/js/src/vm/Interpreter.cpp:424:10
    #21 0x7f7f35c96478 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) src/js/src/vm/Interpreter.cpp:590:13
    #22 0x7f7f35c9763a in InternalCall(JSContext*, js::AnyInvokeArgs const&, js::CallReason) src/js/src/vm/Interpreter.cpp:618:10
    #23 0x7f7f35c9782d in js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>, js::CallReason) src/js/src/vm/Interpreter.cpp:635:8
    #24 0x7f7f35f04cfb in JS::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, JS::HandleValueArray const&, JS::MutableHandle<JS::Value>) src/js/src/jsapi.cpp:2753:10
    #25 0x7f7f2ebf76d7 in mozilla::dom::EventHandlerNonNull::Call(JSContext*, JS::Handle<JS::Value>, mozilla::dom::Event&, JS::MutableHandle<JS::Value>, mozilla::ErrorResult&) src/objdir-ff-ubsan/dom/bindings/EventHandlerBinding.cpp:267:37
    #26 0x7f7f2f7ebc8f in void mozilla::dom::EventHandlerNonNull::Call<nsCOMPtr<mozilla::dom::EventTarget> >(nsCOMPtr<mozilla::dom::EventTarget> const&, mozilla::dom::Event&, JS::MutableHandle<JS::Value>, mozilla::ErrorResult&, char const*, mozilla::dom::CallbackObject::ExceptionHandling, JS::Realm*) src/objdir-ff-ubsan/dist/include/mozilla/dom/EventHandlerBinding.h:364:12
    #27 0x7f7f2f7d018d in mozilla::JSEventHandler::HandleEvent(mozilla::dom::Event*) src/dom/events/JSEventHandler.cpp:201:12
    #28 0x7f7f2f7a9ef4 in mozilla::EventListenerManager::HandleEventSubType(mozilla::EventListenerManager::Listener*, mozilla::dom::Event*, mozilla::dom::EventTarget*) src/dom/events/EventListenerManager.cpp:1082:22
    #29 0x7f7f2f7ab0ed in mozilla::EventListenerManager::HandleEventInternal(nsPresContext*, mozilla::WidgetEvent*, mozilla::dom::Event**, mozilla::dom::EventTarget*, nsEventStatus*, bool) src/dom/events/EventListenerManager.cpp:1274:17
    #30 0x7f7f2f7de377 in mozilla::EventTargetChainItem::HandleEvent(mozilla::EventChainPostVisitor&, mozilla::ELMCreationDetector&) src/dom/events/EventDispatcher.cpp:356:17
    #31 0x7f7f2f79dae2 in mozilla::EventTargetChainItem::HandleEventTargetChain(nsTArray<mozilla::EventTargetChainItem>&, mozilla::EventChainPostVisitor&, mozilla::EventDispatchingCallback*, mozilla::ELMCreationDetector&) src/dom/events/EventDispatcher.cpp:558:16
    #32 0x7f7f2f7a0728 in mozilla::EventDispatcher::Dispatch(nsISupports*, nsPresContext*, mozilla::WidgetEvent*, mozilla::dom::Event*, nsEventStatus*, mozilla::EventDispatchingCallback*, nsTArray<mozilla::dom::EventTarget*>*) src/dom/events/EventDispatcher.cpp:1056:11
    #33 0x7f7f2f7a3719 in mozilla::EventDispatcher::DispatchDOMEvent(nsISupports*, mozilla::WidgetEvent*, mozilla::dom::Event*, nsPresContext*, nsEventStatus*) src/dom/events/EventDispatcher.cpp
    #34 0x7f7f2d8b7937 in nsINode::DispatchEvent(mozilla::dom::Event&, mozilla::dom::CallerType, mozilla::ErrorResult&) src/dom/base/nsINode.cpp:1119:17
    #35 0x7f7f2f7b3355 in mozilla::dom::EventTarget::DispatchEvent(mozilla::dom::Event&) src/dom/events/EventTarget.cpp:178:13
    #36 0x7f7f2f754b31 in mozilla::AsyncEventDispatcher::Run() src/dom/events/AsyncEventDispatcher.cpp:69:12
    #37 0x7f7f291605cc in mozilla::SchedulerGroup::Runnable::Run() src/xpcom/threads/SchedulerGroup.cpp:282:20
    #38 0x7f7f29192d24 in nsThread::ProcessNextEvent(bool, bool*) src/xpcom/threads/nsThread.cpp:1241:14
    #39 0x7f7f2919984e in NS_ProcessNextEvent(nsIThread*, bool) src/xpcom/threads/nsThreadUtils.cpp:486:10
    #40 0x7f7f2a593d2e in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) src/ipc/glue/MessagePump.cpp:87:21
    #41 0x7f7f2a3d69e4 in MessageLoop::Run() src/ipc/chromium/src/base/message_loop.cc:290:3
    #42 0x7f7f3189c75a in nsBaseAppShell::Run() src/widget/nsBaseAppShell.cpp:137:27
    #43 0x7f7f35993899 in XRE_RunAppShell() src/toolkit/xre/nsEmbedFunctions.cpp:946:20
    #44 0x7f7f2a595341 in mozilla::ipc::MessagePumpForChildProcess::Run(base::MessagePump::Delegate*) src/ipc/glue/MessagePump.cpp:237:9
    #45 0x7f7f2a3d69e4 in MessageLoop::Run() src/ipc/chromium/src/base/message_loop.cc:290:3
    #46 0x7f7f35992ce7 in XRE_InitChildProcess(int, char**, XREChildData const*) src/toolkit/xre/nsEmbedFunctions.cpp:781:34
    #47 0x55ee6229e1c5 in content_process_main(mozilla::Bootstrap*, int, char**) src/browser/app/../../ipc/contentproc/plugin-container.cpp:56:28
    #48 0x55ee6229e3ef in main src/browser/app/nsBrowserApp.cpp:303:18
Flags: in-testsuite?

Hi Henri,
could you take a look on this?

Flags: needinfo?(hsivonen)

This ends up calling memcmp(nullptr, nullptr, 0), which one might expect to just return (and, AFAICT, in practice it does). However, C says that it's UB for either of the first two arguments to be null even when the third argument is zero.

Flags: needinfo?(hsivonen)
Assignee: nobody → hsivonen
Status: NEW → ASSIGNED
Pushed by hsivonen@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/de7592c208f4
Avoid passing nullptr to memcmp and memcpy even with 0 length. r=alchen
Status: ASSIGNED → RESOLVED
Closed: 4 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla73
You need to log in before you can comment on or make changes to this bug.