8281275: Upgrading from 8 to 11 no longer accepts '/' as filepath separator in gc paths

Reviewed-by: shade, dcubed
This commit is contained in:
David Holmes 2022-02-10 23:23:48 +00:00
parent 58c2bd3158
commit 84868e39be
2 changed files with 28 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2022, 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
@ -365,9 +365,9 @@ bool LogConfiguration::parse_command_line_arguments(const char* opts) {
// Find the next colon or quote
char* next = strpbrk(str, ":\"");
#ifdef _WINDOWS
// Skip over Windows paths such as "C:\..."
// Handle both C:\... and file=C:\..."
if (next != NULL && next[0] == ':' && next[1] == '\\') {
// Skip over Windows paths such as "C:\..." and "C:/...".
// Handles both "C:\..." and "file=C:\...".
if (next != NULL && next[0] == ':' && (next[1] == '\\' || next[1] == '/')) {
if (next == str + 1 || (strncmp(str, "file=", 5) == 0)) {
next = strpbrk(next + 1, ":\"");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2022, 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
@ -359,6 +359,29 @@ TEST_VM_F(LogConfigurationTest, parse_command_line_arguments) {
ret = jio_snprintf(buf, sizeof(buf), ":%s", TestLogFileName);
ASSERT_NE(-1, ret);
EXPECT_TRUE(LogConfiguration::parse_command_line_arguments(buf));
#ifdef _WINDOWS
// We need to test the special-case parsing for drive letters in
// log file paths e.g. c:\log.txt and c:/log.txt. Our temp directory
// based TestLogFileName should already be the \ format (we print it
// below to visually verify) so we only need to convert to /.
printf("Checked: %s\n", buf);
// First disable logging so the current log file will be closed and we
// can delete it, so that UL won't try to perform log file rotation.
// The rotated file would not be auto-deleted.
set_log_config(TestLogFileName, "all=off");
delete_file(TestLogFileName);
// now convert \ to /
char* current_pos = strchr(buf,'\\');
while (current_pos != nullptr) {
*current_pos = '/';
current_pos = strchr(current_pos + 1, '\\');
}
printf("Checking: %s\n", buf);
EXPECT_TRUE(LogConfiguration::parse_command_line_arguments(buf));
#endif
}
// Test split up log configuration arguments