Skip to content

Memory Corruption in boost::network::uri::decode #501

Closed

Description

@zeroinside

Hi.
During some research on library, I have found, that vulnerability in function boost::network::uri::decode can be used in Denial Of Service attacks.
Issue exist when user pass to in_begin argument few "%" characters. It results in out-of-bound read from null pointer.
For example:
std::string foo;
boost::network::uri::decode("%%%%%%%%%%%%%%%%", back_inserter(foo));
if (_it == '%') {
++it; <= PTR+1
value_type v0 = detail::letter_to_hex(_it);
++it; <= PTR+1
value_type v1 = detail::letter_to_hex(*it);
++it; <= PTR+1

Activity

  1. deanberris commented on Mar 3, 2015

    @deanberris
    Member

    In what version of the library are you seeing this @zeroinside? Thanks for reporting this BTW.

  2. zeroinside commented on Mar 3, 2015

    @zeroinside
    Author

    Currently I'm using 0.11.0, but I've downloaded the 0.11.1 and boost::network::uri::decode is unchanged.

  3. deanberris commented on Mar 3, 2015

    @deanberris
    Member

    Okay, thanks @zeroinside -- do you have a fix, preferably with a test case that you can put in a pull request that I can merge (and release soon) against the 0.11-devel branch?

  4. zeroinside commented on Mar 3, 2015

    @zeroinside
    Author

    Test Case:
    #include
    #include
    #include <boost/network/uri.hpp>
    #include <boost/network/uri/uri_io.hpp>

    int main () {
    std::string foo;
    boost::network::uri::decode("%%%%%%%%%%%%%%%%", back_inserter(foo));

    return 0;
    }

    PATH:
    /usr/local/include/boost/network/uri/decode.hpp

    template <class InputIterator, class OutputIterator>
    OutputIterator decode(const InputIterator &in_begin,
    const InputIterator &in_end,
    const OutputIterator &out_begin) {
    typedef typename boost::iterator_value::type value_type;

    InputIterator it = in_begin;
    OutputIterator out = out_begin;
    while (it != in_end) {
    if(_it==NULL) // Check for the end of string
    break;
    if (_it == '%') {
    ++it;
    value_type v0 = detail::letter_to_hex(_it);
    ++it;
    value_type v1 = detail::letter_to_hex(_it);
    ++it;
    _out++ = 0x10 * v0 + v1;
    } else if (_it == '+') {
    *out++ = ' ';
    ++it;
    } else {
    *out++ = *it++;
    }
    }
    return out;
    }

    Please test the path, if it doesn't cause a regression.

  5. zeroinside commented on Mar 3, 2015

    @zeroinside
    Author

    Sorry, github removes some special chars, like *.
    Pathed function is available @ http://pastebin.com/z6BCq6NK

  6. zeroinside commented on Mar 3, 2015

    @zeroinside
    Author
  7. zeroinside commented on Mar 3, 2015

    @zeroinside
    Author

    Sorry for my fault in path, it's incomplete, variable *it should be checked every time when pointer is incremented.
    I think You should path it your own way.

  8. deanberris commented on Mar 4, 2015

    @deanberris
    Member

    Can you put these in a pull request please @zeroinside?

  9. zeroinside commented on Mar 4, 2015

    @zeroinside
    Author

    I'm a newbie on github:), please do it yourself.

  10. griwes commented on Mar 4, 2015

    @griwes

    s/path/patch/ FTFY

  11. deanberris commented on Mar 4, 2015

    @deanberris
    Member

    So, you can give this a try: http://cpp-netlib.org/process.html

    I'm asking so that we can get proper history on the commits, and explicit granting of copyrights to you licensed under the Boost Software License. This is why I haven't looked at the patches you've put up in pastebin. 😄

    If you can't do this for whatever reason, maybe @glynos can try and fix it? Or I can try if I get the time to do it, which is very scarce for me at the moment. 😦

  12. deanberris commented on Sep 11, 2015

    @deanberris
    Member

    This looks like a serious issue that warrants a proper pull request to fix. Any takers?

  13. susnux commented on Apr 8, 2016

    @susnux

    I think this can be closed, it is fixed since 0.12-RC2 with commit: be97dfe
    (Pull request #553 )

    (Except you want also a fix for the 0.11 branch)

  14. glynos commented on Apr 8, 2016

    @glynos
    Member

    We don't intend to apply any new fixes on 0.11 any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions