-
Notifications
You must be signed in to change notification settings - Fork 11
Handle soft links on library paths #334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Scan-Build Report
Bug Summary
Reports
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR addresses a bug where the Java profiler could accidentally patch itself when its library path contains symbolic links. The fix uses realpath() to resolve symbolic links before comparing library paths.
Changes:
- Added
realpath()call to resolve the profiler's own library path ininitialize() - Added
realpath()call to resolve each library's path before comparing with the profiler's path inpatch_library_unlocked() - Handles special cases like virtual files (e.g., [vdso]) that cannot be resolved
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| bool ret = dladdr(caller_address, &info); | ||
| assert(ret); | ||
| _profiler_name = strdup(info.dli_fname); | ||
| _profiler_name = realpath(info.dli_fname, nullptr); |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error handling: If realpath() fails (returns nullptr), _profiler_name will be set to nullptr. This could cause crashes later when _profiler_name is used in strcmp() at line 96. The code should handle this error case, either by falling back to the original path from strdup() or by logging an error and handling the null case appropriately.
| _profiler_name = realpath(info.dli_fname, nullptr); | |
| char* resolved_path = realpath(info.dli_fname, nullptr); | |
| if (resolved_path != nullptr) { | |
| _profiler_name = resolved_path; | |
| } else { | |
| // Fall back to the original path if realpath fails | |
| _profiler_name = strdup(info.dli_fname); | |
| } |
|
@jbachorik I've opened a new pull request, #335, to work on those changes. Once the pull request is ready, I'll request review from you. |
(cherry picked from commit 43c671b)
What does this PR do?:
Handle soft link paths in path comparison.
Motivation:
Java profiler patches library's
pthread_create() @pltentry, but not itself. If java profiler's library is on a path with soft link, path comparison may fail that results it accidentally patches itself.Additional Notes:
How to test the change?:
libjavaprofiler.soto a path with soft link, run `java -agentpath:${PATH_WITH_SOFT_LINK}/libjavaProfiler.so=start,filter=1,wall=10ms,cpu=10ms,file=profile.jfr $JAVA_APPLICATIONFor Datadog employees:
credentials of any kind, I've requested a review from
@DataDog/security-design-and-guidance.Unsure? Have a question? Request a review!