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
This commit is contained in:
Wu Yan 2021-10-22 16:23:25 +00:00 committed by Naoto Sato
parent 4dec8fc4cc
commit 88bbf3c2e6
4 changed files with 233 additions and 145 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -38,6 +38,7 @@
#include "jvm.h"
#include "TimeZone_md.h"
#include "path_util.h"
static char *isFileIdentical(char* buf, size_t size, char *pathname);
@ -77,6 +78,33 @@ static const char *ETC_ENVIRONMENT_FILE = "/etc/environment";
#if defined(__linux__) || defined(MACOSX)
/*
* remove repeated path separators ('/') in the given 'path'.
*/
static void
removeDuplicateSlashes(char *path)
{
char *left = path;
char *right = path;
char *end = path + strlen(path);
for (; right < end; right++) {
// Skip sequence of multiple path-separators.
while (*right == '/' && *(right + 1) == '/') {
right++;
}
while (*right != '\0' && !(*right == '/' && *(right + 1) == '/')) {
*left++ = *right++;
}
if (*right == '\0') {
*left = '\0';
break;
}
}
}
/*
* Returns a pointer to the zone ID portion of the given zoneinfo file
* name, or NULL if the given string doesn't contain "zoneinfo/".
@ -296,6 +324,8 @@ getPlatformTimeZoneID()
return NULL;
}
linkbuf[len] = '\0';
removeDuplicateSlashes(linkbuf);
collapse(linkbuf);
tz = getZoneName(linkbuf);
if (tz != NULL) {
tz = strdup(tz);