Skip to content
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

Fix segmentation fault when adding + 1 to a null pointer #30

Conversation

tim661811
Copy link
Contributor

Description

While upgrading libosdp from version 2.1.0 to 3.0.8, I encountered a segmentation fault. The fault occurred almost immediately upon entering the __cp_setup function.

Investigation

After analyzing the issue, I traced the problem to the LOG_PRINT macro. Specifically, the error originated in the __logger_log function, where the return value of the strrchr function was not properly handled.

As per the documentation, strrchr returns a pointer to the last occurrence of the specified character, or a null pointer if the character is not found. In this case, the file variable already contained just the filename (not the full file path), meaning no path separator was present. Consequently, strrchr returned a null pointer. Adding 1 to a null pointer caused the segmentation fault.

Fix

I updated the code to handle cases where strrchr returns a null pointer, ensuring the macro doesn't attempt to dereference or manipulate invalid pointers.

Copy link
Member

@sidcha sidcha left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the fix

@sidcha sidcha merged commit e54ba78 into goToMain:master Jan 27, 2025
1 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants