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

A couple of fixes for issues discovered by GCC analyzer #529

Merged
merged 4 commits into from
Nov 28, 2024

Conversation

mrc0mmand
Copy link
Member

This addresses three issues (and one potential one) found by GCC analyzer after my adventures with OpenScanHub. See the respective commits for more details.

As that's a way to a certain segmentation fault.

Discovered by GCC analyzer:

[74/84] Linking target src/polkitagent/polkit-agent-helper-1
../src/polkitagent/polkitagenthelper-pam.c: In function ‘send_to_helper’:
../src/polkitagent/polkitagenthelper-pam.c:46:10: warning: use of NULL where non-null expected [CWE-476] [-Wanalyzer-null-argument]
   46 |   len2 = strlen(tmp2);
      |          ^

[83/84] Linking target src/programs/pkexec
../src/programs/pkexec.c: In function ‘main’:
../src/programs/pkexec.c:817:7: warning: use of NULL ‘command_line’ where non-null expected [CWE-476] [-Wanalyzer-null-argument]
  817 |   if (strlen(command_line) > 80)
      |       ^
push_action_and_details() never used the "error" argument internally, so
it always remained set to NULL, which would lead to nasty surprises in
the error paths.

Found by GCC analyzer:

[84/84] Linking target src/polkitbackend/polkitd
../src/polkitbackend/polkitbackendduktapeauthority.c: In function ‘polkit_backend_common_js_authority_check_authorization_sync’:
../src/polkitbackend/polkitbackendduktapeauthority.c:1015:7: warning: dereference of NULL ‘error’ [CWE-476] [-Wanalyzer-null-dereference]
 1015 |       polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority),
The error object in this case should always be allocated if
polkit_authority_check_authorization_finish() returns NULL, so let's
convey this message to static analyzers as well.

Another potential "solution" for this could be checking the error object
instead of the result one when returning from
polkit_authority_check_authorization_finish() (like it's done in the
respective example - src/examples/cancel.c), but we already have a
precedent of using g_assert() on the error object for this in our
codebase.

This should address following warning from GCC analyzer:

[75/89] Linking target src/polkit/libpolkit-gobject-1.so.0.0.0
../src/polkit/polkitpermission.c: In function ‘changed_check_cb’:
../src/polkit/polkitpermission.c:485:7: warning: dereference of NULL ‘error’ [CWE-476] [-Wanalyzer-null-dereference]
  485 |       g_warning ("Error checking authorization for action id %s: %s",
      |       ^
@siteshwar
Copy link

Thanks! This should be enabled in Packit configurations too. Please add this line to Packit configurations:

csmock_args: --gcc-add-flag=-flto=auto

@siteshwar
Copy link

OpenScanHub task shows 4 fixed warnings after LTO was enabled: https://openscanhub.fedoraproject.org/task/25069/log/fixed.html

So, it seems to work as expected. Thanks!

GCC analyzer in some cases depends on information provided by LTO to
generate accurate results, but the LTO support in GCC analyzer is still
experimental, so it's not enabled by default. In Polkit, however, this
seems to work pretty well, so let's tell OSH to build our code with LTO
when running GCC analyzer.
@vmihalko vmihalko merged commit 252b7f3 into polkit-org:main Nov 28, 2024
36 checks passed
@mrc0mmand mrc0mmand deleted the appease-gccs-analyzer branch November 28, 2024 14:38
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.

3 participants