public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/104369] New: False positive from -Wanalyzer-use-of-uninitialized-value with realloc moving buffer
@ 2022-02-03 14:55 dmalcolm at gcc dot gnu.org
2022-02-03 22:48 ` [Bug analyzer/104369] " cvs-commit at gcc dot gnu.org
2022-02-03 22:52 ` dmalcolm at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2022-02-03 14:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104369
Bug ID: 104369
Summary: False positive from
-Wanalyzer-use-of-uninitialized-value with realloc
moving buffer
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: analyzer
Assignee: dmalcolm at gcc dot gnu.org
Reporter: dmalcolm at gcc dot gnu.org
Target Milestone: ---
Created attachment 52343
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52343&action=edit
Reduced reproducer
The attached reproducer emits two false positives from
-Wanalyzer-use-of-uninitialized-value, both "when 'realloc' succeeds, moving
buffer", the first of which is:
<source>: In function 'main':
<source>:79:34: warning: use of uninitialized value '*pollfds.fd' [CWE-457]
[-Wanalyzer-use-of-uninitialized-value]
79 | pollfds[nsockets - 1].fd = accept(pollfds[0].fd, &remote, &len);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'main': events 1-7
|
| 62 | if (!pollfds) {
| | ^
| | |
| | (1) following 'false' branch (when 'pollfds' is non-NULL)...
|......
| 67 | rc = ppoll(pollfds, nsockets, NULL, NULL);
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | (2) ...to here
|......
| 74 | newpollfds = realloc(pollfds, nsockets * sizeof(*pollfds));
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | (3) when 'realloc' succeeds, moving buffer
| | (4) region created on heap here
| 75 | if (!newpollfds) {
| | ~
| | |
| | (5) following 'false' branch (when 'newpollfds' is
non-NULL)...
|......
| 78 | pollfds = newpollfds;
| | ~~~~~~~~~~~~~~~~~~~~
| | |
| | (6) ...to here
| 79 | pollfds[nsockets - 1].fd = accept(pollfds[0].fd, &remote,
&len);
| |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | (7) use of uninitialized value
'*pollfds.fd' here
|
On Compiler Explorer:
https://godbolt.org/z/EKrnsoaY4
>From downstream report:
https://bugzilla.redhat.com/show_bug.cgi?id=2047926#c5
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug analyzer/104369] False positive from -Wanalyzer-use-of-uninitialized-value with realloc moving buffer
2022-02-03 14:55 [Bug analyzer/104369] New: False positive from -Wanalyzer-use-of-uninitialized-value with realloc moving buffer dmalcolm at gcc dot gnu.org
@ 2022-02-03 22:48 ` cvs-commit at gcc dot gnu.org
2022-02-03 22:52 ` dmalcolm at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-02-03 22:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104369
--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by David Malcolm <dmalcolm@gcc.gnu.org>:
https://gcc.gnu.org/g:3ef328c293a336df0aead2d72c0c5ed9781a9861
commit r12-7040-g3ef328c293a336df0aead2d72c0c5ed9781a9861
Author: David Malcolm <dmalcolm@redhat.com>
Date: Wed Feb 2 16:39:12 2022 -0500
analyzer: fixes to realloc-handling [PR104369]
This patch fixes various issues with how -fanalyzer handles "realloc"
seen when debugging PR analyzer/104369.
Previously it wasn't correctly copying over the contents of the old
buffer for the success-with-move case, leading to false
-Wanalyzer-use-of-uninitialized-value diagnostics.
I also noticed that -fanalyzer failed to properly handle "realloc" for
cases where the ptr's region had unknown dynamic extents, and an ICE
for the case where a tainted value is used as a realloc size argument.
This patch fixes these issues, including the false uninit diagnostics
seen in PR analyzer/104369.
gcc/analyzer/ChangeLog:
PR analyzer/104369
* engine.cc (exploded_graph::process_node): Use the node for any
diagnostics, avoiding ICE if a bifurcation update adds a
saved_diagnostic, such as for a tainted realloc size.
* region-model-impl-calls.cc
(region_model::impl_call_realloc::success_no_move::update_model):
Require the old pointer to be non-NULL to be able successfully
grow in place. Use model->deref_rvalue rather than
maybe_get_region
to support the old pointer being symbolic.
(region_model::impl_call_realloc::success_with_move::update_model):
Likewise. Add a constraint that the new pointer != the old
pointer.
Use a sized_region when setting the value of the new region.
Handle the case where we don't know the dynamic size of the old
region by marking the new region as unknown.
* sm-taint.cc (tainted_allocation_size::tainted_allocation_size):
Update assertion to also allow for MEMSPACE_UNKNOWN.
(tainted_allocation_size::emit): Likewise.
(region_model::check_dynamic_size_for_taint): Likewise.
gcc/testsuite/ChangeLog:
PR analyzer/104369
* gcc.dg/analyzer/pr104369-1.c: New test.
* gcc.dg/analyzer/pr104369-2.c: New test.
* gcc.dg/analyzer/realloc-3.c: New test.
* gcc.dg/analyzer/realloc-4.c: New test.
* gcc.dg/analyzer/taint-realloc.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug analyzer/104369] False positive from -Wanalyzer-use-of-uninitialized-value with realloc moving buffer
2022-02-03 14:55 [Bug analyzer/104369] New: False positive from -Wanalyzer-use-of-uninitialized-value with realloc moving buffer dmalcolm at gcc dot gnu.org
2022-02-03 22:48 ` [Bug analyzer/104369] " cvs-commit at gcc dot gnu.org
@ 2022-02-03 22:52 ` dmalcolm at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2022-02-03 22:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104369
David Malcolm <dmalcolm at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |FIXED
--- Comment #2 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Should be fixed by the above commit.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-03 22:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-03 14:55 [Bug analyzer/104369] New: False positive from -Wanalyzer-use-of-uninitialized-value with realloc moving buffer dmalcolm at gcc dot gnu.org
2022-02-03 22:48 ` [Bug analyzer/104369] " cvs-commit at gcc dot gnu.org
2022-02-03 22:52 ` dmalcolm at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).