Skip to content

Commit

Permalink
8281275: Upgrading from 8 to 11 no longer accepts '/' as filepath sep…
Browse files Browse the repository at this point in the history
…arator in gc paths

Reviewed-by: mdoerr
Backport-of: 84868e39be4522ba87e603beea0f8da9efa43b6d
GoeLin committed Mar 24, 2022
1 parent 6aecb15 commit 8eeba89
Showing 2 changed files with 28 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/hotspot/share/logging/logConfiguration.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, 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
@@ -339,9 +339,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, ":\"");
}
25 changes: 24 additions & 1 deletion test/hotspot/gtest/logging/test_logConfiguration.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, 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
@@ -273,6 +273,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

1 comment on commit 8eeba89

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.