Skip to content

Commit d532019

Browse files
author
Joachim Kern
committed
8347143: [aix] Fix strdup use in os::dll_load
Reviewed-by: mdoerr, clanger, kbarrett
1 parent dfd215b commit d532019

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/hotspot/os/aix/os_aix.cpp

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2012, 2024 SAP SE. All rights reserved.
3+
* Copyright (c) 2012, 2025 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -1068,21 +1068,24 @@ static void* dll_load_library(const char *filename, int *eno, char *ebuf, int eb
10681068
// If filename matches <name>.so, and loading fails, repeat with <name>.a.
10691069
void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
10701070
void* result = nullptr;
1071-
char* const file_path = strdup(filename);
1072-
char* const pointer_to_dot = strrchr(file_path, '.');
10731071
const char old_extension[] = ".so";
10741072
const char new_extension[] = ".a";
1075-
STATIC_ASSERT(sizeof(old_extension) >= sizeof(new_extension));
10761073
// First try to load the existing file.
1077-
int eno=0;
1074+
int eno = 0;
10781075
result = dll_load_library(filename, &eno, ebuf, ebuflen);
1079-
// If the load fails,we try to reload by changing the extension to .a for .so files only.
1076+
// If the load fails, we try to reload by changing the extension to .a for .so files only.
10801077
// Shared object in .so format dont have braces, hence they get removed for archives with members.
1081-
if (result == nullptr && eno == ENOENT && pointer_to_dot != nullptr && strcmp(pointer_to_dot, old_extension) == 0) {
1082-
snprintf(pointer_to_dot, sizeof(old_extension), "%s", new_extension);
1083-
result = dll_load_library(file_path, &eno, ebuf, ebuflen);
1078+
if (result == nullptr && eno == ENOENT) {
1079+
const char* pointer_to_dot = strrchr(filename, '.');
1080+
if (pointer_to_dot != nullptr && strcmp(pointer_to_dot, old_extension) == 0) {
1081+
STATIC_ASSERT(sizeof(old_extension) >= sizeof(new_extension));
1082+
char* tmp_path = os::strdup(filename);
1083+
size_t prefix_size = pointer_delta(pointer_to_dot, filename, 1);
1084+
os::snprintf(tmp_path + prefix_size, sizeof(old_extension), "%s", new_extension);
1085+
result = dll_load_library(tmp_path, &eno, ebuf, ebuflen);
1086+
os::free(tmp_path);
1087+
}
10841088
}
1085-
FREE_C_HEAP_ARRAY(char, file_path);
10861089
return result;
10871090
}
10881091

0 commit comments

Comments
 (0)