RFR: 8348323: Corrupted timezone string in JVM crash log [v2]

Dhamoder Nalla dhanalla at openjdk.org
Mon Jan 27 18:38:52 UTC 2025


On Fri, 24 Jan 2025 20:51:41 GMT, Dhamoder Nalla <dhanalla at openjdk.org> wrote:

>> Add a error check to "wcstombs" otherwise the "buf" prints junk or corrupted string.
>> 
>> Test performed: 
>> 1. "jcmd < jvm pid > VM.info" for different JVM versions
>
> Dhamoder Nalla has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:
> 
>  - Merge branch 'master' into Corrupted-Timezone-String
>  - update year in copyright header
>  - Fix to Timezone string corruption

> > When we look at this kind of thing in future it will be no timezone printed that means we have hit an existing problem fetching a valid timezone.
> 
> Just a thought, can't use this logic to make it more clear ? :
> 
> ```diff
> diff --git a/src/hotspot/share/runtime/os.cpp b/src/hotspot/share/runtime/os.cpp
> index 094d68e1a84..aea9aee5adf 100644
> --- a/src/hotspot/share/runtime/os.cpp
> +++ b/src/hotspot/share/runtime/os.cpp
> @@ -1213,8 +1213,12 @@ void os::print_date_and_time(outputStream *st, char* buf, size_t buflen) {
>      wchar_t w_buf[80];
>      size_t n = ::wcsftime(w_buf, 80, L"%Z", &tz);
>      if (n > 0) {
> -      ::wcstombs(buf, w_buf, buflen);
> -      st->print("Time: %s %s", timestring, buf);
> +      bool success = (::wcstombs(buf, w_buf, buflen) != (size_t)-1);
> +      if (success) {
> +        st->print("Time: %s %s", timestring, buf);
> +      } else {
> +        st->print("Time: %s (Error: Failed to convert timezone to multi-byte string)", timestring);
> +      }
>      } else {
>        st->print("Time: %s", timestring);
>      }
> ```

Thanks @offamitkumar, 
This logic will result in the time not being printed, whereas we were only intending to skip the time zone string.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/23246#issuecomment-2616597540


More information about the hotspot-runtime-dev mailing list