mirror of
https://github.com/pumpitupdev/pumptools.git
synced 2026-09-29 10:18:14 +03:00
fix: harden shared IO library path lookup
PR #86 derives the mapping-file directory from dladdr's dli_fname. The initial implementation assumes that the resolved name contains a directory separator. If the loader returns a bare soname, the truncation loop reduces it to its first character and reports success, causing a bogus mapping-file lookup instead of using the executable-directory fallback. Locate the final separator before copying, preserve the filesystem root, reject names that do not identify a directory, and validate the length of the returned directory rather than requiring room for the complete library filename. Link the four PIUIO and PIUBTN keyboard and joystick targets directly with libdl so their dladdr dependency remains explicit on the supported older glibc environment.
This commit is contained in:
committed by
voidderef
parent
7a72487742
commit
9c1983a9e4
@@ -12,4 +12,4 @@ set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-fPIC")
|
||||
# Remove library name "lib" prefix
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} ptapi-io-piubtn-joystick-util io-util util)
|
||||
target_link_libraries(${PROJECT_NAME} ptapi-io-piubtn-joystick-util io-util util dl)
|
||||
|
||||
@@ -12,4 +12,4 @@ set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-fPIC")
|
||||
# Remove library name "lib" prefix
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} ptapi-io-piubtn-keyboard-util io-util util)
|
||||
target_link_libraries(${PROJECT_NAME} ptapi-io-piubtn-keyboard-util io-util util dl)
|
||||
|
||||
@@ -12,4 +12,4 @@ set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-fPIC")
|
||||
# Remove library name "lib" prefix
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} ptapi-io-piuio-joystick-util io-util util)
|
||||
target_link_libraries(${PROJECT_NAME} ptapi-io-piuio-joystick-util io-util util dl)
|
||||
|
||||
@@ -12,4 +12,4 @@ set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-fPIC")
|
||||
# Remove library name "lib" prefix
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} ptapi-io-piuio-keyboard-util io-util util)
|
||||
target_link_libraries(${PROJECT_NAME} ptapi-io-piuio-keyboard-util io-util util dl)
|
||||
|
||||
+11
-12
@@ -210,6 +210,8 @@ bool util_proc_get_folder_path_shared_object(
|
||||
void *symbol, char *buffer, size_t size)
|
||||
{
|
||||
Dl_info info;
|
||||
const char *separator;
|
||||
size_t folder_len;
|
||||
|
||||
if (!symbol || !buffer || size == 0) {
|
||||
return false;
|
||||
@@ -219,23 +221,20 @@ bool util_proc_get_folder_path_shared_object(
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strlen(info.dli_fname) >= size) {
|
||||
separator = strrchr(info.dli_fname, '/');
|
||||
|
||||
if (!separator) {
|
||||
return false;
|
||||
}
|
||||
|
||||
strcpy(buffer, info.dli_fname);
|
||||
folder_len = separator == info.dli_fname ? 1 : separator - info.dli_fname;
|
||||
|
||||
// If shared object in the root folder, keep the single /
|
||||
size_t pos = strlen(buffer) - 1;
|
||||
while (pos > 0 && buffer[pos] != '/') {
|
||||
buffer[pos] = '\0';
|
||||
pos--;
|
||||
if (folder_len >= size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// delete /
|
||||
if (pos > 0) {
|
||||
buffer[pos] = '\0';
|
||||
}
|
||||
memcpy(buffer, info.dli_fname, folder_len);
|
||||
buffer[folder_len] = '\0';
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -257,4 +256,4 @@ void util_proc_log_info()
|
||||
log_info(
|
||||
"========================================================================"
|
||||
"========================");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,8 @@ bool util_proc_get_folder_path_executable_no_ld_linux(
|
||||
* @param symbol Pointer to any symbol in the target shared object.
|
||||
* @param buffer Buffer to read the path into.
|
||||
* @param size Size of the buffer.
|
||||
* @return True on success, false on failure.
|
||||
* @return True on success, false when the symbol cannot be resolved, the
|
||||
* resolved name has no folder, or the buffer is too small.
|
||||
*/
|
||||
bool util_proc_get_folder_path_shared_object(
|
||||
void *symbol, char *buffer, size_t size);
|
||||
|
||||
Reference in New Issue
Block a user