HomeClusterLabs Projects

Low: libcrmcommon: Fix Coverity false positive pcmk__file_contents()

Description

Low: libcrmcommon: Fix Coverity false positive pcmk__file_contents()

The suppression comment has always been of an incorrect format (see link
below), but we're suddenly getting a Coverity error for string_null
(non-null-terminated string) at the caller. The fread() line of
pcmk__file_contents() is identified as the string_null_source.

It's a false positive: calloc() sets every byte to zero before we write
to at most the first length bytes. However, there does not appear to
be any way to suppress the false positive within the called function.
Among the things that have been tried are:

  • // coverity[string_null_source] before the fread() line
  • // coverity[string_null_source:FALSE] before the fread() line
  • // coverity[string_null_source:SUPPRESS] before the fread() line
  • // coverity[-string_null_taint] before the pcmk__file_contents() definition
  • // coverity[-string_null_return] before the pcmk__file_contents() definition

It's not really clear why Coverity just now started identifying this
error. The relevant code has not changed recently. The error began with
the "NULL-check argument to pcmkmark_xml_created()" commit. My best
guess: create_xml_node() and add_node_copy() are in the call chain of
pcmk
verify_digest(). Perhaps Coverity could not properly analyze
pcmk__verify_digest() and identify it as a string_null_sink, prior to
that commit.

If we ever want to suppress false positives at the source, and
annotations aren't getting the job done, we could try writing a custom
model and calling cov-make-library as part of the coverity-corp make
target. See the "Customizing Coverity" doc for details on writing and
using custom models, and the "Checker Reference" doc under STRING_NULL
for an example model. Not worth it for now IMO.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>

Details

Provenance
nrwahl2Authored on May 19 2023, 1:23 AM
Parents
rP77067aec95ee: Refactor: based: cib_cleanup_query() frees output if not current CIB
Branches
Unknown
Tags
Unknown