Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: unify implementations of Utf8Value, TwoByteValue, etc. #6357

Closed
wants to merge 1 commit into from

Commits on Apr 28, 2016

  1. src: unify implementations of Utf8Value etc.

    Unify the common code of `Utf8Value`, `TwoByteValue`, `BufferValue`
    and `StringBytes::InlineDecoder` into one class. Always make the
    result zero-terminated for the first three.
    
    This fixes two problems in passing:
    
    * When the conversion of the input value to String fails,
      make the buffer zero-terminated anyway. Previously, this would
      have resulted in possibly reading uninitialized data in multiple
      places in the code. An instance of that problem can be reproduced
      by running e.g.
      `valgrind node -e 'net.isIP({ toString() { throw Error() } })'`.
    * Previously, `BufferValue` copied one byte too much from the source,
      possibly resulting in an out-of-bounds memory access.
      This can be reproduced by running e.g.
      `valgrind node -e \
        'fs.openSync(Buffer.from("node".repeat(8192)), "r")'`.
    
    Further minor changes:
    * This lifts the `out()` method of `StringBytes::InlineDecoder`
      to the common class so that it can be used when using the
      overloaded `operator*` does not seem appropiate.
    * Hopefully clearer variable names.
    * Add checks to make sure the length of the data does not exceed
      the allocated storage size, including the possible null terminator.
    addaleax committed Apr 28, 2016
    Configuration menu
    Copy the full SHA
    2ae9282 View commit details
    Browse the repository at this point in the history