uriparser / uriparser

:hocho: Strictly RFC 3986 compliant URI parsing and handling library written in C89; moved from SourceForge to GitHub

Home Page:https://uriparser.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[CVE-2021-46142] uriNormalizeSyntax* may free stack memory in out-of-memory situation when handling URIs containing empty segments

autofuzzoss opened this issue · comments

A bug was found within the uriparser. Though it might not be an intended use of the relevant API, the bug can still produce critical issues within a program using uriparser. It would be best if the affected logic is checked beforehand.
The bug was found with a fuzzer based on the test-code"NormalizeSyntaxExMm"

_crash log

==3440==ERROR: AddressSanitizer: SEGV on unknown address 0x0000004d9be0 (pc 0x00000041ca94 bp 0x000000000000 sp 0x7ffd2468e6e0 T0)
==3440==The signal is caused by a WRITE memory access.
    #0 0x41ca94 in __asan::Allocator::Deallocate(void*, unsigned long, unsigned long, __sanitizer::BufferedStackTrace*, __asan::AllocType)
    #1 0x493d41 in free 
    #2 0x4c6892 in (anonymous namespace)::countingFree(UriMemoryManagerStruct*, void*) 
    #3 0x7faf2e1ac4b2 in uriNormalizeSyntaxExMmA_ 

Steps to reproduce:

  1. git clone https://github.com/uriparser/uriparser.git
  2. cd uriparser & mkdir build & cd build
  3. Build
    cmake -DCMAKE_BUILD_TYPE=Release -DURIPARSER_BUILD_DOCS:BOOL=OFF -DBUILD_SHARED_LIBS:BOOL=ON ..
    make -j8
  4. Download the attached file(2.cpp)
  5. Build TEST CODE (2.cpp)
    clang++ -g -fsanitize=address,fuzzer-no-link -o 2 2.cpp -I uriparser/include/ -I uriparser/ -Luriparser/build -luriparser
  6. Run
    LD_LIBRARY_PATH=uriparser/build/ ./2

OS:ubuntu 18.04
uriparser_poc2.tar.gz

@afosscontact thanks for the detailed report, I will have a closer look.

@afosscontact confirming as a bug, fixed by pull request #124 (along with issue #121). Thanks for the report again! 🙏

Thank you for the fix
Is it possible to issue CVE ID?
If you are not possible, should you ask MITRE?

@afosscontact speaking for #121 and #122, I can request a CVE (or two) once the security impact of these two bugs is clear. If you could add a security assessment to the two issues — detailed or brief — that would help. Also, giving credit to your real name both inside uriparser and/or in the mitre submission form is still an option, if you're comfortable disclosing your name to either me and mitre (by e-mail) or everyone here. Or you submit to mitre and only they get your name or no one. I'd also be curious, what the context of this work of yours was, if you'd be up for sharing that with me off-list. Thanks in advance.

PS: @afosscontact the two bugs are closed as fixed now. I'm still happy to team up with you on the CVE subject as mentioned above.