Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8201649

Remove dubious call_jio_print in ostream.cpp

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 11
    • 11
    • hotspot
    • None
    • 11
    • b11

      With its current implementation, defaultStream::write(const char* s, size_t len) might randomly truncate the data written.

      The reason is that it makes use of the method jio_print(const char* s) to actually write the data to the output stream. jio_print(const char* s) expects a zero terminated string, whereas the input to defaultStream::write is a pointer to a string buffer which is not necessarily null terminated and a length field.

      Currently, defaultStream::write checks if by occasion the next char after the buffer is null. If true it calls jio_print with the input buffer. If false, the fallback is to call function "call_jio_print" which copies the input buffer into a temporary fixed size buffer, adding a terminating null. If the input data is larger than the buffer, it obviously gets truncated.

      Since defaultStream::write is the only user of jio_print, we can change its implementation/signature, to work with buffer/length input arguments and internally use a format string with precision field set to buffer length.

            clanger Christoph Langer
            clanger Christoph Langer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: