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

java_lang_String::print can segfault with uninitialized string

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • 9
    • 9
    • hotspot
    • generic
    • generic

      Hi Chris,

      maybe you could sneak this patch into upstream, it’s a fix for an issue where the VM segfaults when it tries to print a string with a null value array.
      It confused me for a while while looking for another problem...
      I think it got introduced when the String class was changed - because now it needs to look at the value array to determine the length.

      - Lukas

      in src/share/vm/classfile/javaClasses.cpp:
      @@ -464,15 +464,15 @@
      void java_lang_String::print(oop java_string, outputStream* st) {
        assert(java_string->klass() == SystemDictionary::String_klass(), "must be java_string");
        typeArrayOop value = java_lang_String::value(java_string);
      - int offset = java_lang_String::offset(java_string);
      - int length = java_lang_String::length(java_string);
      -
      - int end = MIN2(length, 100);
      +
        if (value == NULL) {
          // This can happen if, e.g., printing a String
          // object before its initializer has been called
          st->print_cr("NULL");
        } else {
      + int offset = java_lang_String::offset(java_string);
      + int length = java_lang_String::length(java_string);
      + int end = MIN2(length, 100);
          st->print("\"");
          for (int index = 0; index < length; index++) {
            st->print("%c", value->char_at(index + offset));

            hseigel Harold Seigel (Inactive)
            twisti Christian Thalinger (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: