Skip to content

CA-407106: fix various XHA warnings from the Clang static analyzer#22

Merged
GeraldEV merged 9 commits intoxenserver:masterfrom
edwintorok:private/edvint/warnings
Mar 5, 2025
Merged

CA-407106: fix various XHA warnings from the Clang static analyzer#22
GeraldEV merged 9 commits intoxenserver:masterfrom
edwintorok:private/edvint/warnings

Conversation

@edwintorok
Copy link
Contributor

@edwintorok edwintorok commented Feb 21, 2025

Fixes for:

  • CA-407106: Fix various build and static analyzer warnings
  • CA-407106: Fix potential uninitialized value during timeout
  • CA-407106: Close file descriptor
  • CA-407106: Use backtrace and backtrace_symbols
  • CA-407106: Fix 'variable set but not used' warnings
  • CA-407106: Avoid using deprecated sigset and sigignore functions
  • CA-407106: Fix build with clang: remove nested functions
  • CA-407106: Fix missing arguments to self_fence
  • Update .gitignore with CodeChecker and binary files
  • CA-406953: fix more undefined behaviour
  • CA-406953: Fix format string warnings
  • CA-406953: Use fixed size integer types
  • Tell the compiler that log_message takes a format string as argument
  • Update .gitignore with CodeChecker files

@freddy77
Copy link
Collaborator

A description would be nice

@freddy77
Copy link
Collaborator

Can you clean the binary files?

@edwintorok
Copy link
Contributor Author

Can you clean the binary files?

Thanks for spotting that, looks like gitignore isn't set correctly, I'll fix that.

Comment on lines 8 to 9
compile_commands.json
.cache/
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would avoid adding specific tool settings.

@edwintorok edwintorok force-pushed the private/edvint/warnings branch 2 times, most recently from c8347fc to d7919a1 Compare February 24, 2025 15:22
Copy link
Collaborator

@rosslagerwall rosslagerwall left a comment

Choose a reason for hiding this comment

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

A few minor comments, but this generally seems fine.

@edwintorok edwintorok force-pushed the private/edvint/warnings branch from dbbe629 to 0f69670 Compare March 5, 2025 16:14
Signed-off-by: Edwin Török <edwin.torok@cloud.com>
`sm_fence` didn't declare what arguments it takes, but this is
deprecated.

```
../include/sm.h:368:1: warning: a function declaration without a prototype is deprecated in all versions of C and is treated as a zero-parameter prototype in C23, conflicting with a subsequent definition [-Wdeprecated-non-prototype]
sm.c:530:1: note: conflicting prototype is here
```

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
Nested functions are a GCC-only extension and are not supported by clang
and clangd at all.

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
Use `sigaction` and `sigprocmask` instead.
There is also `signal`, but the manpage says to not use it.
Indeed `sigaction` has more reliable semantics by default in POSIX (e.g. it blocks the signal while you are handling it,
so you don't reenter it while it is executing).

Unfortunately the new functions are more verbose, so introduce a loop for setting up the signal handlers.

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
These are either set again later to another value, or never read.

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
The code always gets 10 return addresses, however we can't know for sure that we actually have 10 addresses on the stack.
We might try to read beyond the stack and crash.

The compiler warns about this:
```
log.c:452:9: warning: calling ‘__builtin_frame_address’ with a nonzero argument is unsafe [-Wframe-address]
  452 |     if (__builtin_frame_address(x) == 0)                \
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
log.c:471:5: note: in expansion of macro ‘FILL_RETURN_ADDRESS’
```

Instead use a GNU libc specific function: backtrace and backtrace_symbols to get a stacktrace safely.
This is a short live program and would close it on exit anyway,
but we don't want to ignore this kind of error in the rest of the program.

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
If a timeout is reached, then the loop is never entered, and 'index' is uninitialized.
All the logging calls would use an uninitialized value, and later `my_sfdomain` would also be uninitialized
and various decisions would be taken based on its state.

Ensure that these variables are initialized at least once in the loop by moving the timeout condition.

It is very unlikely that this'd actually happen, but without this change the static analyzer
wouldn't be able to spot other bugs that'd leave these values uninitialized.

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
Also disable warnings we can't/don't want to fix now:
* clang-diagnostic-reserved-macro-identifier
 The bug is in Xen, it mandates using `__XEN_TOOLS__` in `sysctl.h`


Signed-off-by: Edwin Török <edwin.torok@cloud.com>
@edwintorok edwintorok force-pushed the private/edvint/warnings branch from 0f69670 to 8944196 Compare March 5, 2025 16:20
@GeraldEV GeraldEV merged commit a2582e1 into xenserver:master Mar 5, 2025
4 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.

4 participants