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

8273111: Default timezone should return zone ID if /etc/localtime is valid but not canonicalization on linux #5327

Closed
wants to merge 5 commits into from

Conversation

@wuyan0
Copy link

@wuyan0 wuyan0 commented Sep 1, 2021

Hi,
Please help me review the change to enhance getting time zone ID from /etc/localtime on linux.

We use realpath instead of readlink to obtain the link name of /etc/localtime, because readlink can only read the value of a symbolic of link, not the canonicalized absolute pathname.

For example, the value of /etc/localtime is "../usr/share/zoneinfo//Asia/Shanghai", then the linkbuf obtained by readlink is "../usr/share/zoneinfo//Asia/Shanghai", and then the call of getZoneName(linkbuf) will get "/Asia/Shanghai", not "Asia/Shanghai", which consider as invalid in ZoneInfoFile.getZoneInfo(). Using realpath, you can get “/usr/share/zoneinfo/Asia/Shanghai“ directly from “/etc/localtime“.

Thanks,
wuyan


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8273111: Default timezone should return zone ID if /etc/localtime is valid but not canonicalization on linux

Reviewers

Contributors

  • Sun Jianye <sunjianye@huawei.com>

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/5327/head:pull/5327
$ git checkout pull/5327

Update a local copy of the PR:
$ git checkout pull/5327
$ git pull https://git.openjdk.java.net/jdk pull/5327/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 5327

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/5327.diff

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Sep 1, 2021

👋 Welcome back wuyan! 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.

Loading

@openjdk openjdk bot added the rfr label Sep 1, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Sep 1, 2021

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

  • core-libs

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.

Loading

@openjdk openjdk bot added the core-libs label Sep 1, 2021
@wuyan0
Copy link
Author

@wuyan0 wuyan0 commented Sep 1, 2021

/contributor add Sun Jianye sunjianye@huawei.com

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Sep 1, 2021

@wuyan0 Could not parse Sun Jianye sunjianye@huawei.com as a valid contributor.
Syntax: /contributor (add|remove) [@user | openjdk-user | Full Name <email@address>]. For example:

  • /contributor add @openjdk-bot
  • /contributor add duke
  • /contributor add J. Duke <duke@openjdk.org>

Loading

@mlbridge
Copy link

@mlbridge mlbridge bot commented Sep 1, 2021

Loading

@wuyan0
Copy link
Author

@wuyan0 wuyan0 commented Sep 1, 2021

/contributor add Sun Jianye sunjianye@huawei.com

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Sep 1, 2021

@wuyan0
Contributor Sun Jianye <sunjianye@huawei.com> successfully added.

Loading

@AlanBateman
Copy link
Contributor

@AlanBateman AlanBateman commented Sep 1, 2021

I haven't come across this configuration like but changing it to use realpath seem reasonable.

Loading

@fweimer-rh
Copy link

@fweimer-rh fweimer-rh commented Sep 1, 2021

Using realpath instead of readlink will change results on systems which use symbolic links instead of hard links to de-duplicate the timezone files. For example, on Debian, if UTC is configured (/etc/localtime points to /usr/share/zoneinfo/UTC), I think the result will be Etc/UTC instead of UTC after this change. But I have not actually tested this.

Loading

DEFAULT_ZONEINFO_FILE);
/* canonicalize the path */
char resolvedpath[PATH_MAX + 1];
char *path = realpath(DEFAULT_ZONEINFO_FILE, resolvedpath);

Choose a reason for hiding this comment

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

You really should use realpath with NULL as the second argument, to avoid any risk of buffer overflow. Future C library headers may warn about non-null arguments here.

Loading

Copy link
Author

@wuyan0 wuyan0 Sep 2, 2021

Choose a reason for hiding this comment

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

Ok, Thanks. I will refer to the implementation of os::Posix::realpath to fix it if we still use realpath.

char* os::Posix::realpath(const char* filename, char* outbuf, size_t outbuflen) {

Loading

@naotoj
Copy link
Member

@naotoj naotoj commented Sep 1, 2021

/label i18n

Loading

@openjdk openjdk bot added the i18n label Sep 1, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Sep 1, 2021

@naotoj
The i18n label was successfully added.

Loading

@naotoj
Copy link
Member

@naotoj naotoj commented Sep 1, 2021

The change looks reasonable. Please test your fix with macOS as well.

Loading

@wuyan0
Copy link
Author

@wuyan0 wuyan0 commented Sep 2, 2021

I haven't come across this configuration like but changing it to use realpath seem reasonable.

Thanks, this scenario comes from our customers.

Using realpath instead of readlink will change results on systems which use symbolic links instead of hard links to de-duplicate the timezone files. For example, on Debian, if UTC is configured (/etc/localtime points to /usr/share/zoneinfo/UTC), I think the result will be Etc/UTC instead of UTC after this change. But I have not actually tested this.

We tested it on ubuntu, it does have this kind of problem, thank you for your reminder. realpath doesn't seem to be suitable here, maybe we could directly process the previous linkbuf to remove the extra'.' and'/'.

The change looks reasonable. Please test your fix with macOS as well.

Thanks, the test on macOS is passed.

Loading

@wuyan0
Copy link
Author

@wuyan0 wuyan0 commented Sep 9, 2021

Hi, we directly process the characters in linkbuf instead of realpath. And we reuse collapse() to process the '.' and '..' in linkbuf.

We tested some cases about /etc/localtime, and it works well. Test cases and results are in the attachment.
testcase.log
result.log

Loading

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Oct 7, 2021

@wuyan0 This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

Loading

@wuyan0
Copy link
Author

@wuyan0 wuyan0 commented Oct 9, 2021

Hi, @naotoj, Could you do me a favor to review the patch?

Loading

}
}
}

Copy link
Member

@naotoj naotoj Oct 11, 2021

Choose a reason for hiding this comment

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

There are a few *(right + 1) references in the loops. Is there any possibility that it would run over the buffer?

Loading

Copy link
Author

@wuyan0 wuyan0 Oct 13, 2021

Choose a reason for hiding this comment

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

It wouldn't run over the buffer. Here end points to '\0'. At line 94 and line 99, right is less than end, so right + 1 is at most end. At line 103, if right equals end, *right != '\0' will be false and !(*right == '/' && *(right + 1) == '/') will not executed.

Loading

void splitNames(char *names, char **ix);
void joinNames(char *names, int nc, char **ix);
Copy link
Member

@naotoj naotoj Oct 11, 2021

Choose a reason for hiding this comment

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

Are these functions, collapsible, splitNames and joinNames have to be non-static?

Loading

Copy link
Author

@wuyan0 wuyan0 Oct 13, 2021

Choose a reason for hiding this comment

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

You are right, thanks for your suggestions, I'll change these functions to static in next commit.

Loading

naotoj
naotoj approved these changes Oct 13, 2021
Copy link
Member

@naotoj naotoj left a comment

Looks good. Thanks for the fix.

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Oct 13, 2021

@wuyan0 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:

8273111: Default timezone should return zone ID if /etc/localtime is valid but not canonicalization on linux

Co-authored-by: Sun Jianye <sunjianye@huawei.com>
Reviewed-by: naoto, mli

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 130 new commits pushed to the master branch:

  • 4dec8fc: 8275645: [JVMCI] avoid unaligned volatile reads on AArch64
  • 4e647aa: 8275416: G1: remove unnecessary make_referent_alive in precleaning phase
  • dd622e5: 8275783: G1: fix incorrect region type documentation in HeapRegionType
  • b2128a9: 8263155: Allow additional contents for DMG
  • 1efe946: 8275712: Hashtable literal_size functions are broken
  • fab3d6c: 8275761: Backout: JDK-8274794 Print all owned locks in hs_err file
  • c978ca8: 8275344: -Xcheck:jni produces some warnings in the LCMS.c
  • 6a466fe: 8202056: Expand serial warning to check for bad overloads of serial-related methods and ineffectual fields
  • 4e9dd4b: 8275384: Change nested classes in jdk.jconsole to static nested classes
  • 0961de4: 8275347: ciReplay: staticfield lines not properly terminated
  • ... and 120 more: https://git.openjdk.java.net/jdk/compare/d9e03e42afbb2e5115b67accfffad4938b8314b1...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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@naotoj, @Hamlin-Li) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

Loading

@openjdk openjdk bot added the ready label Oct 13, 2021
@@ -77,6 +78,39 @@ static const char *ETC_ENVIRONMENT_FILE = "/etc/environment";

#if defined(__linux__) || defined(MACOSX)

/*
* remove repeated path separators ('/') in the giving 'path'.

Choose a reason for hiding this comment

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

given?

Loading

Copy link
Author

@wuyan0 wuyan0 Oct 19, 2021

Choose a reason for hiding this comment

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

Thanks, fix it.

Loading

*/
for (; right < end; right++) {
if (*right == '/' && *(right + 1) == '/') break;
}

Choose a reason for hiding this comment

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

Is this for loop necessary? Seems it's ok to merge with the nested loop below.

Loading

Copy link
Author

@wuyan0 wuyan0 Oct 19, 2021

Choose a reason for hiding this comment

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

Thanks for your suggestion, this for loop is indeed unnecessary. Removed it.

Loading

{
char *left = path;
char *right = path;
char *end = path + strlen(path);

Choose a reason for hiding this comment

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

"char* end"? better to align with existing code style

Loading

Copy link
Author

@wuyan0 wuyan0 Oct 19, 2021

Choose a reason for hiding this comment

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

OK, fixed it.

Loading

Copy link

@Hamlin-Li Hamlin-Li left a comment

looks good

Loading

@wuyan0
Copy link
Author

@wuyan0 wuyan0 commented Oct 20, 2021

/integrate

Loading

@openjdk openjdk bot added the sponsor label Oct 20, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Oct 20, 2021

@wuyan0
Your change (at version ba9cc65) is now ready to be sponsored by a Committer.

Loading

@wuyan0
Copy link
Author

@wuyan0 wuyan0 commented Oct 22, 2021

Hi, @naotoj, I pushed the new commit, do you need to review again?

Loading

naotoj
naotoj approved these changes Oct 22, 2021
Copy link
Member

@naotoj naotoj left a comment

Looks good. Thanks for the fix.

Loading

@naotoj
Copy link
Member

@naotoj naotoj commented Oct 22, 2021

/sponsor

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Oct 22, 2021

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

  • 4dec8fc: 8275645: [JVMCI] avoid unaligned volatile reads on AArch64
  • 4e647aa: 8275416: G1: remove unnecessary make_referent_alive in precleaning phase
  • dd622e5: 8275783: G1: fix incorrect region type documentation in HeapRegionType
  • b2128a9: 8263155: Allow additional contents for DMG
  • 1efe946: 8275712: Hashtable literal_size functions are broken
  • fab3d6c: 8275761: Backout: JDK-8274794 Print all owned locks in hs_err file
  • c978ca8: 8275344: -Xcheck:jni produces some warnings in the LCMS.c
  • 6a466fe: 8202056: Expand serial warning to check for bad overloads of serial-related methods and ineffectual fields
  • 4e9dd4b: 8275384: Change nested classes in jdk.jconsole to static nested classes
  • 0961de4: 8275347: ciReplay: staticfield lines not properly terminated
  • ... and 120 more: https://git.openjdk.java.net/jdk/compare/d9e03e42afbb2e5115b67accfffad4938b8314b1...master

Your commit was automatically rebased without conflicts.

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Oct 22, 2021

@naotoj @wuyan0 Pushed as commit 88bbf3c.

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

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants