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

JDK-8312612: handle WideCharToMultiByte return values #15015

Closed
wants to merge 2 commits into from

Conversation

MBaesken
Copy link
Member

@MBaesken MBaesken commented Jul 25, 2023

The function WideCharToMultiByte is used at a number of places of the JDK codebase for conversion purposes.
Unfortunately, the function might fail because of various reasons, so the return value must be checked to avoid undefined behavior or even crashes.
see
https://learn.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-widechartomultibyte
especially
https://learn.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-widechartomultibyte#return-value

At most places in the coding the return values are already checked, but some are missing.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8312612: handle WideCharToMultiByte return values (Bug - P3)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/15015/head:pull/15015
$ git checkout pull/15015

Update a local copy of the PR:
$ git checkout pull/15015
$ git pull https://git.openjdk.org/jdk.git pull/15015/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 15015

View PR using the GUI difftool:
$ git pr show -t 15015

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/15015.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 25, 2023

👋 Welcome back mbaesken! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 25, 2023
@openjdk
Copy link

openjdk bot commented Jul 25, 2023

@MBaesken The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Jul 25, 2023
@mlbridge
Copy link

mlbridge bot commented Jul 25, 2023

Webrevs

Copy link
Contributor

@RealCLanger RealCLanger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, two minor suggestions.

if (nb > 0) {
JNU_ThrowByName(env, PRINTEREXCEPTION_STR, errStr);
} else {
JNU_ThrowByName(env, PRINTEREXCEPTION_STR, "Secondary error while OS message extraction");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better: secondary error during OS message extraction

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I borrowed it from here (other error handling of WideCharToMultiByte)


jdk/src/java.base/windows/native/libjava/ProcessImpl_md.c 

102          const char *errorMessage = "Secondary error while OS message extraction";

should I change both locations ?

} else {
delete[] lpUTF8Str;
}
return NULL;
Copy link
Contributor

@RealCLanger RealCLanger Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better move return NULL into else block?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better remove the else block :-) ?

@openjdk
Copy link

openjdk bot commented Jul 28, 2023

@MBaesken This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8312612: handle WideCharToMultiByte return values

Reviewed-by: clanger

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 38 new commits pushed to the master branch:

  • a3d6723: 8311033: [macos] PrinterJob does not take into account Sides attribute
  • 4ae5a3e: 8306446: java/lang/management/ThreadMXBean/Locks.java transient failures
  • cad6114: 8304954: SegmentedCodeCache fails when using large pages
  • ba645da: 8313082: Enable CreateCoredumpOnCrash for testing in makefiles
  • c27c877: 8302017: Allocate BadPaddingException only if it will be thrown
  • c55d29f: 8312626: Resolve multiple definition of 'start_timer' when statically linking JDK native libraries with user code
  • 0ca2bfd: 8311104: dangling-gsl warning in libwixhelper.cpp
  • c05ba48: 8313250: Exclude java/foreign/TestByteBuffer.java on AIX
  • 169b6e3: 8313174: Create fewer predictable port clashes in management tests
  • 8650026: 8310033: Clarify return value of Java Time compareTo methods
  • ... and 28 more: https://git.openjdk.org/jdk/compare/91fe03232760ae0a9b56456f2f5f5ee6e483e4ef...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 28, 2023
Copy link
Contributor

@RealCLanger RealCLanger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better.

@MBaesken
Copy link
Member Author

Hi Christoph, thanks for the review.
The Windows aarch64 build errors seems to be unrelated (but should maybe still be addressed, but other issue).

@MBaesken
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Jul 28, 2023

Going to push as commit d9559f9.
Since your change was applied there have been 40 commits pushed to the master branch:

  • 34173ff: 8312574: jdk/jdk/jfr/jvm/TestChunkIntegrity.java fails with timeout
  • 47c4b99: 8312121: Fix -Wconversion warnings in tribool.hpp
  • a3d6723: 8311033: [macos] PrinterJob does not take into account Sides attribute
  • 4ae5a3e: 8306446: java/lang/management/ThreadMXBean/Locks.java transient failures
  • cad6114: 8304954: SegmentedCodeCache fails when using large pages
  • ba645da: 8313082: Enable CreateCoredumpOnCrash for testing in makefiles
  • c27c877: 8302017: Allocate BadPaddingException only if it will be thrown
  • c55d29f: 8312626: Resolve multiple definition of 'start_timer' when statically linking JDK native libraries with user code
  • 0ca2bfd: 8311104: dangling-gsl warning in libwixhelper.cpp
  • c05ba48: 8313250: Exclude java/foreign/TestByteBuffer.java on AIX
  • ... and 30 more: https://git.openjdk.org/jdk/compare/91fe03232760ae0a9b56456f2f5f5ee6e483e4ef...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jul 28, 2023
@openjdk openjdk bot closed this Jul 28, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jul 28, 2023
@openjdk
Copy link

openjdk bot commented Jul 28, 2023

@MBaesken Pushed as commit d9559f9.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

2 participants