Skip to content

plugins: fix error_string construction#2273

Merged
BareosBot merged 2 commits intobareos:masterfrom
florian-at-bareos:dev/fburger/master/fix-error-strings
Jun 5, 2025
Merged

plugins: fix error_string construction#2273
BareosBot merged 2 commits intobareos:masterfrom
florian-at-bareos:dev/fburger/master/fix-error-strings

Conversation

@florian-at-bareos
Copy link
Contributor

@florian-at-bareos florian-at-bareos commented May 13, 2025

This PR fixes a bug introduced with commit ce9f5bc, see #225.

PyUnicode_AsUTF8 can return NULL and doing std::string(NULL) will crash.
With the changes of this PR we explicitly do a null-pointer check before constructing a std::string.

Fixes bareos/internal#225: ce9f5bc introduces creation of std::string from potential nullptr

Thank you for contributing to the Bareos Project!

Please check

  • Short description and the purpose of this PR is present above this paragraph
  • Your name is present in the AUTHORS file (optional)

If you have any questions or problems, please give a comment in the PR.

Helpful documentation and best practices

Checklist for the reviewer of the PR (will be processed by the Bareos team)

Make sure you check/merge the PR using devtools/pr-tool to have some simple automated checks run and a proper changelog record added.

General
  • Is the PR title usable as CHANGELOG entry?
  • Purpose of the PR is understood
  • Commit descriptions are understandable and well formatted
  • Required backport PRs have been created
  • Correct milestone is set
Source code quality
  • Source code changes are understandable
  • Variable and function names are meaningful
  • Code comments are correct (logically and spelling)
  • Required documentation changes are present and part of the PR

Copy link
Contributor

@sebsura sebsura left a comment

Choose a reason for hiding this comment

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

Looks good. Just added a small nit to think about.

@florian-at-bareos florian-at-bareos force-pushed the dev/fburger/master/fix-error-strings branch from c5e0a51 to ff9fe57 Compare May 21, 2025 14:37
@florian-at-bareos florian-at-bareos marked this pull request as ready for review May 23, 2025 10:08
@florian-at-bareos florian-at-bareos requested a review from sebsura May 23, 2025 10:09
@florian-at-bareos florian-at-bareos requested a review from sebsura May 26, 2025 12:31
@florian-at-bareos
Copy link
Contributor Author

florian-at-bareos commented Jun 4, 2025

If I interpret this correctly type == NULL implies that value == NULL and traceback == NULL, see https://docs.python.org/3/c-api/exceptions.html#c.PyErr_Fetch.

@sebsura
Copy link
Contributor

sebsura commented Jun 4, 2025

That is true, but as we do not check whether traceback or value are null before calling the function, we can still pass a null type into the python function.

Looking into the cpython doc i get the following (for Py_BuildValue):

O (object) [PyObject *]

    Pass a Python object untouched but create a new [strong reference](https://docs.python.org/3/glossary.html#term-strong-reference) to it (i.e. its reference count is incremented by one).
    If the object passed in is a NULL pointer, it is assumed that this was caused because the call producing the argument found an error and set an exception.
    Therefore, [Py_BuildValue()](https://docs.python.org/3/c-api/arg.html#c.Py_BuildValue) will return NULL but won’t raise an exception.
    If no exception has been raised yet, [SystemError](https://docs.python.org/3/library/exceptions.html#SystemError) is set.

so this isnt fatal, but still not great. It looks like we should also be using Py_Restore(...) once we are dont with the result of Py_Fetch(...), so its probably best to just leave this as is and rework it completely at a later point.
After all almost all of these functions are deprecated in 3.12, so this will need to get replaced soon anyways.

@sebsura
Copy link
Contributor

sebsura commented Jun 4, 2025

Looks like github didnt show me your last commit, so now there is actually a check for that :)

florian-at-bareos and others added 2 commits June 5, 2025 07:09
PyUnicode_AsUTF8 can return NULL and doing std::string(NULL) will crash.

Fixes bareos#225: ce9f5bc introduces creation of std::string from
potential nullptr
@BareosBot BareosBot force-pushed the dev/fburger/master/fix-error-strings branch from 761d6f9 to 1fa6413 Compare June 5, 2025 07:09
@BareosBot BareosBot merged commit 169dd92 into bareos:master Jun 5, 2025
@sebsura sebsura mentioned this pull request Jun 24, 2025
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants