Skip to content

Fix some Coverity false positives - #4103

Merged
clumens merged 79 commits into
ClusterLabs:mainfrom
nrwahl2:nrwahl2-coverity
Jul 30, 2026
Merged

Fix some Coverity false positives#4103
clumens merged 79 commits into
ClusterLabs:mainfrom
nrwahl2:nrwahl2-coverity

Conversation

@nrwahl2

@nrwahl2 nrwahl2 commented May 5, 2026

Copy link
Copy Markdown
Contributor

This fixes INCOMPLETE_DEALLOCATOR false positives for mainloop_gio_destroy() and another one that I don't recall. It also fixes a longstanding const fields issue with lrmd_event_data_t.

Edit: The INCOMPLETE_DEALLOCATOR false positives are still present. I'm probably going to have to figure out how to open a support case to make those go away. However, this PR fixes other Coverity issues and does some cleanup.

@nrwahl2
nrwahl2 requested a review from clumens May 5, 2026 18:53
clumens
clumens previously approved these changes May 5, 2026
Comment thread lib/lrmd/lrmd_client.c
@clumens

clumens commented May 5, 2026

Copy link
Copy Markdown
Contributor

Man, coverity's being picky right now.

@nrwahl2

nrwahl2 commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

Man, coverity's being picky right now.

Yeah, and the new errors are actually ones that I dropped in the "Drop unused Coverity annotations" commit. The analysis output said those were unused. And at the time, when I re-ran Coverity, the errors did not reappear. Now they do.

@clumens
clumens self-requested a review May 5, 2026 21:23
@clumens
clumens dismissed their stale review May 5, 2026 21:23

New coverity things to look at

@nrwahl2
nrwahl2 force-pushed the nrwahl2-coverity branch from cd3813a to 273ec06 Compare May 14, 2026 09:23
@nrwahl2 nrwahl2 changed the title Fix a couple of Coverity false positives for INCOMPLETE_DEALLOCATOR Fix some Coverity false positives May 14, 2026
@nrwahl2
nrwahl2 marked this pull request as draft May 14, 2026 09:28
@nrwahl2
nrwahl2 marked this pull request as ready for review May 14, 2026 09:30
@nrwahl2
nrwahl2 force-pushed the nrwahl2-coverity branch from 273ec06 to 670054b Compare May 14, 2026 09:30
@nrwahl2
nrwahl2 force-pushed the nrwahl2-coverity branch from 670054b to cba948f Compare May 25, 2026 23:04
@nrwahl2

nrwahl2 commented May 25, 2026

Copy link
Copy Markdown
Contributor Author

Just let me know where you want to break this up.

Comment thread devel/Makefile.am
Comment thread include/crm/lrmd_events.h
/*! exit failure reason string from resource agent operation */
const char *exit_reason;
char *exit_reason;
} lrmd_event_data_t;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lrmd_event_data_t is public API. Can you make this change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Feels like a gray area. Strictly speaking, no. If an external program assigned a literal string or a value that's declared as const char * to one of these lrmd_event_data_t fields, then I presume that program would fail to compile after this change.

However, if an external program were doing that, and then it called lrmd_free_event() (as it typically should), then it would most likely seg fault.

The constructors are allocating memory to these const char * fields, and more dangerously the destructor is freeing them.

Comment thread include/crm/services_internal.h
Comment thread daemons/fenced/fenced_commands.c Outdated
Comment thread daemons/fenced/fenced_commands.c
Comment thread tools/crm_resource.c
Comment thread lib/pacemaker/pcmk_agents.c
Comment thread devel/cov_models.c

// See comment in cov_nodefs.h for an explanation
void
g_clear_pointer(void **ptr, void (*destroy_fn)(void *))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there any reason why this doesn't have the exact same prototype as in glib (void g_clear_pointer gpointer *pp, GDestroyNotify destroy))?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same reason I defined NULL explicitly. The includes aren't getting included when I call cov-make-library, so those typedefs aren't available. As best I can figure out, I'd have to specify a compiler, and then maybe specify -I options for include directories.

Or I could add the typedefs myself. That's actually what Coverity does for the models that it ships. See /opt/cov-sa-2026.3/coverity-models-1.7.0/src/glib2.c.

Comment thread lib/common/output_text.c
Comment thread lib/common/actions.c
g_regex_unref(regex);
g_match_info_unref(match_info);
g_strfreev(matches);
return result;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think these changes are fine, but in the interest of minimizing them, it seems like it should be pretty easy to get rid of trailing whitespace.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I did it this way so that a transition magic string whose key (the last field) ends in trailing whitespace would fail validation in decode_transition_key(). It's an invalid key if its length isn't 36.

Leading whitespace will be rejected by decode_transition_magic().

@clumens clumens added the review: in progress PRs that are currently being reviewed label Jun 1, 2026
@nrwahl2
nrwahl2 marked this pull request as draft June 3, 2026 21:02
@nrwahl2
nrwahl2 force-pushed the nrwahl2-coverity branch from cba948f to b5b080f Compare June 3, 2026 21:14
@nrwahl2

nrwahl2 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on main and resolved conflicts. Leaving in draft state for now, since I haven't addressed all of Chris's review.

@nrwahl2
nrwahl2 force-pushed the nrwahl2-coverity branch from b5b080f to 1b55802 Compare June 18, 2026 03:50
@nrwahl2

nrwahl2 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Rebased to resolve conflicts again

@nrwahl2 nrwahl2 added waiting for author Review has been provided, and we're waiting for a response from the author of the pull request and removed review: in progress PRs that are currently being reviewed labels Jul 15, 2026
@nrwahl2
nrwahl2 force-pushed the nrwahl2-coverity branch from 1b55802 to f25347b Compare July 29, 2026 21:48
@nrwahl2

nrwahl2 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Updated to address review. I need to update again to resolve conflicts. I didn't want to clutter the diff with conflict resolution.

nrwahl2 added 6 commits July 29, 2026 14:49
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
annotations-warnings.txt in the coverity-TAG/output directory says the
return overflow annotation is unused.

Also flag the replica->child error as a false positive, rather than
simply suppressing it. bundle_data->child->priv->children is a list of
non-NULL items, and we've already dereferenced replica->child before we
hit the line that Coverity complains about.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
qb_ipcc_is_connected() returns QB_FALSE for a NULL argument.
pcmk__ipc_free_client_buffer() does nothing when its argument's buffer
field is NULL.

Also remove a layer of nesting.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Commit 4facb96 introduced much of this complexity. The commit message
says "Make mainloop_gio_destroy() tollerant of being called
re-entrantly". However, there seems to be no way this could happen.
Pacemaker is single-threaded, and the destroy_fn can't return control
back to the main loop. Control returns to the main loop when
mainloop_gio_destroy() returns.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
nrwahl2 added 22 commits July 29, 2026 14:53
No new errors appear when I remove these. At least as of Coverity
2026.3, Coverity models the abort() function.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
This doesn't introduce any new errors after refactoring.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
This one is currently unused, but it's an odd one; it seems to come and
go with other changes.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
This doesn't introduce any new errors. It's safer to assert.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
This doesn't introduce any new errors.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
We always passed false.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The sole caller already ensures that *dest is NULL. We assert like this
in some other places where we expect an output argument to point to a
NULL pointer.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
This avoids the HAVE_SSCANF_M check. It has the side effect of allowing
whitespace characters within passwords. Also, we no longer strip leading
or trailing whitespace. A password on my Linux system may have leading
or trailing whitespace or whitespace in the middle.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
To replace all the HAVE_*CURSES constants and reduce some redundancy.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
We use it in crm_mon_curses.c, but we've never checked for it at build
time. Instead, we've always tried to use regular curses (non-ncurses) if
ncurses is not available. NCURSES_CONST won't be defined there.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
INSTALL.md already documents the need for ncurses if a user wants to use
crm_mon in interactive mode. Also, we require NCURSES_CONST to be
defined in that case; this has been true since bd203b2.

So we might as well require ncurses explicitly and drop support for
"regular" curses. This shouldn't change behavior.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Technically this changes the behavior of a public API function.
* We now reject transition magic strings that begin with whitespace.
* We now reject transition magic strings whose op_status or op_rc field
  begins with a plus sign. These fields must now consist of an optional
  minus sign followed by digits.
* We now reject transition magic strings whose op_status or op_rc field
  overflows the range of an int.
* We now preserve any whitespace at the end of a transition magic
  string.

These are all side effects of replacing the sscanf() calls with a regex
match and explicit integer parsing.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Nothing uses it anymore.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Coverity was flagging this as an error because it didn't know whether
pcmk__trace() might set entry->notify to NULL. Coverity doesn't have a
model for qb_log_from_external_source(), which pcmk__trace() calls.

We could provide a model, but instead we just drop the "%p", which
doesn't seem helpful.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Coverity thinks that passing replica to g_list_append() can set
replica->child to NULL. Opened support case 03704783 with Black Duck
(Coverity vendor), for them to investigate this further.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
* Use bool instead of gboolean.
* Use const GList *.
* Improve spacing.
* Reduce nesting of conditions and make them more explicit.
* Rename to pcmk__is_set_recursive() to emphasize that this is an
  internal library function.
* Use uint64_t instead of long long for flag.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
We always pass true now.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
This note was added by commit ef49a32 with no explanation. I don't
believe it's ever been part of our documentation, and I'm not sure
whether it's valid or relevant. However, in case it is, I'm reluctant to
lose it.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
@nrwahl2
nrwahl2 marked this pull request as ready for review July 29, 2026 21:54
@nrwahl2
nrwahl2 force-pushed the nrwahl2-coverity branch from f25347b to 67fb49e Compare July 29, 2026 21:57
@nrwahl2

nrwahl2 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Updated to resolve conflicts

@nrwahl2 nrwahl2 added needs attention PRs that someone needs to look at and removed waiting for author Review has been provided, and we're waiting for a response from the author of the pull request labels Jul 30, 2026
@clumens
clumens merged commit 0a945c3 into ClusterLabs:main Jul 30, 2026
1 check passed
@nrwahl2
nrwahl2 deleted the nrwahl2-coverity branch July 30, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs attention PRs that someone needs to look at

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants