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

V39/analyzer extra stuff #4730

Draft
wants to merge 43 commits into
base: master
Choose a base branch
from

Conversation

elliefm
Copy link
Contributor

@elliefm elliefm commented Nov 7, 2023

This sits on top of #4724, will need rebasing once that lands. The real contents here are the commits starting with "WIP".

This contains all the stuff where there's either a real problem that I haven't worked out how to solve properly, or where I needed to add stuff just to shut up a false positive from the static analyzer.

Even with all these commits, a few source files still don't build cleanly with -fanalyze yet. In particular, all the code generated by flex/bison. Also, jmap_contact.c, httpd.c, and http_jwt.testc are others I remember at the time of writing. For these files, I had to compile them individually without -fanalyze due to things I couldn't fix nor shut up.

With these commits, and a lot of CPU time and RAM, you can build all of Cyrus (with exceptions as above) under the analyzer, and successfully run the cunit and cassandane tests.

This used a junk wrapper struct to allocate two structs in a single malloc,
which is confusing to the gcc static analyzer.

Instead, just use two allocations...

Nothing cleans these up, so they would still be leaked in practice, except
that Cyrus never calls this function anyway.
it doesn't understand that we only won't have a *comp if there
was an error already, so just check for *comp too
it doesn't understand that we only won't have a *param if there
was an error already, so just check for *param too
not sure if this helps or is complete
GCC static analyser complains that the year field of due and created
are uninitialized, but only when memcpying them over period.end, even
though it might have just successfully memcpy'd it over period.start
without complaint.

Even weirder: replacing the memcpy's with assignments stops it
complaining, even though it should not have made any difference.

Might be a GCC bug?  But I need to shut it up to get on with fixing
the real complaints...

gcc (Debian 12.2.0-14) 12.2.0

imap/ical_support.c: In function 'icalcomponent_get_utc_timespan':
imap/ical_support.c:1223:25: error: use of uninitialized value '*(unsigned char (*)[40])((char *)&due + offsetof(struct icaltimetype, year))' [CWE-457] [-Werror=analyzer-use-of-uninitialized-value]
 1223 |                         memcpy(&period.end, &due, sizeof(struct icaltimetype));

...

imap/ical_support.c:1251:25: error: use of uninitialized value '*(unsigned char (*)[40])((char *)&created + offsetof(struct icaltimetype, year))' [CWE-457] [-Werror=analyzer-use-of-uninitialized-value]
 1251 |                         memcpy(&period.end, &created, sizeof(struct icaltimetype));
Not sure if this is necessary, but it shuts up the static analyzer...
what does this case really mean?
analyzer doesn't understand that msgdata is only NULL when nmsgs
is zero, but if nmsgs is zero we weren't doing anything anyway.
need to shut it up so i can continue...
analyzer doesn't understand that last is only null when we haven't
found a list head yet...

but surely we need to reset it to null when starting a new list!
assuming these only fail on out-of-memory...
free(NULL) is a no-op, but it looks like the static analyzer's
free wrapper doesn't know that, and treats two calls to free(NULL)
in the same function as if NULL were being freed twice, and then
complains about a double-free!
ckind may be null and _jsunknown_to_vcard does not change that,
but we try to deref it anyway
if no scriptid, we exited above from the parser.invalid check
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.

1 participant