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 throwing exceptions, allow only "safe" types #983

Merged

Conversation

jrohel
Copy link
Contributor

@jrohel jrohel commented Oct 19, 2023

Exceptions were thrown in the code, in which a pointer to text was passed that was no longer in memory at the time the exception was handled.
Fix: Replaced passing char * and const char * with std::string when throwing exception.

To prevent this from happening again, passing only defined "safe" types is now allowed.

@jrohel jrohel linked an issue Oct 19, 2023 that may be closed by this pull request
@jrohel jrohel force-pushed the fix/passing_exceptions_args branch from c4dd9d5 to f9b4dcb Compare October 19, 2023 12:14
@pkratoch pkratoch self-assigned this Oct 19, 2023
@jrohel jrohel force-pushed the fix/passing_exceptions_args branch 2 times, most recently from 9db6573 to ff54c76 Compare October 22, 2023 17:38
@jrohel
Copy link
Contributor Author

jrohel commented Oct 22, 2023

Doc text for concept AllowedErrorArgTypes. Rebased.

The exception stores the passed arguments and uses them in the catch
phase. The problem is that the text to which the saved argument points
may no longer be in memory - is destroyed when the program leaves
the scope of the variable with the text.

A safer solution than passing a pointer to memory is to use
"std::string" and pass it by value.
"move" semantics now works for rvalue arguments.
…ctors

Exceptions were generated in the code, in which a pointer to text was
passed that was no longer in memory at the time the exception was handled.

To prevent this from happening again, passing only defined "safe" types
is now allowed.
@jrohel jrohel force-pushed the fix/passing_exceptions_args branch from ff54c76 to 8ec790d Compare October 25, 2023 09:32
@jrohel
Copy link
Contributor Author

jrohel commented Oct 25, 2023

I added a commit fixing SolvRepo::load_solv_cache method - Compare string content instead of pointers.

@pkratoch
Copy link
Contributor

I added a commit fixing SolvRepo::load_solv_cache method - Compare string content instead of pointers.

Thanks!

@pkratoch pkratoch added this pull request to the merge queue Oct 25, 2023
Merged via the queue into rpm-software-management:main with commit 73443c0 Oct 25, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Some exceptions contain pointers to non-existent data
2 participants