analyzer: fix ICE casued by dup2 in sm-fd.cc[PR106551]
This patch fixes the ICE caused by valid_to_unchecked_state, at analyzer/sm-fd.cc by handling the m_start state in check_for_dup. Tested lightly on x86_64. gcc/analyzer/ChangeLog: PR analyzer/106551 * sm-fd.cc (check_for_dup): handle the m_start state when transitioning the state of LHS of dup, dup2 and dup3 call. gcc/testsuite/ChangeLog: * gcc.dg/analyzer/fd-dup-1.c: New testcases. * gcc.dg/analyzer/fd-uninit-1.c: Remove bogus warning. Signed-off-by: Immad Mir <mirimmad@outlook.com>
This commit is contained in:
parent
04ce2400b3
commit
837142257c
|
@ -971,7 +971,8 @@ fd_state_machine::check_for_dup (sm_context *sm_ctxt, const supernode *node,
|
||||||
state_t state_arg_1 = sm_ctxt->get_state (stmt, arg_1);
|
state_t state_arg_1 = sm_ctxt->get_state (stmt, arg_1);
|
||||||
if (state_arg_1 == m_stop)
|
if (state_arg_1 == m_stop)
|
||||||
return;
|
return;
|
||||||
if (!(is_constant_fd_p (state_arg_1) || is_valid_fd_p (state_arg_1)))
|
if (!(is_constant_fd_p (state_arg_1) || is_valid_fd_p (state_arg_1)
|
||||||
|
|| state_arg_1 == m_start))
|
||||||
{
|
{
|
||||||
check_for_open_fd (sm_ctxt, node, stmt, call, callee_fndecl,
|
check_for_open_fd (sm_ctxt, node, stmt, call, callee_fndecl,
|
||||||
DIRS_READ_WRITE);
|
DIRS_READ_WRITE);
|
||||||
|
@ -983,7 +984,7 @@ fd_state_machine::check_for_dup (sm_context *sm_ctxt, const supernode *node,
|
||||||
case DUP_1:
|
case DUP_1:
|
||||||
if (lhs)
|
if (lhs)
|
||||||
{
|
{
|
||||||
if (is_constant_fd_p (state_arg_1))
|
if (is_constant_fd_p (state_arg_1) || state_arg_1 == m_start)
|
||||||
sm_ctxt->set_next_state (stmt, lhs, m_unchecked_read_write);
|
sm_ctxt->set_next_state (stmt, lhs, m_unchecked_read_write);
|
||||||
else
|
else
|
||||||
sm_ctxt->set_next_state (stmt, lhs,
|
sm_ctxt->set_next_state (stmt, lhs,
|
||||||
|
@ -999,7 +1000,8 @@ fd_state_machine::check_for_dup (sm_context *sm_ctxt, const supernode *node,
|
||||||
if (state_arg_2 == m_stop)
|
if (state_arg_2 == m_stop)
|
||||||
return;
|
return;
|
||||||
/* Check if -1 was passed as second argument to dup2. */
|
/* Check if -1 was passed as second argument to dup2. */
|
||||||
if (!(is_constant_fd_p (state_arg_2) || is_valid_fd_p (state_arg_2)))
|
if (!(is_constant_fd_p (state_arg_2) || is_valid_fd_p (state_arg_2)
|
||||||
|
|| state_arg_2 == m_start))
|
||||||
{
|
{
|
||||||
sm_ctxt->warn (
|
sm_ctxt->warn (
|
||||||
node, stmt, arg_2,
|
node, stmt, arg_2,
|
||||||
|
@ -1011,7 +1013,7 @@ fd_state_machine::check_for_dup (sm_context *sm_ctxt, const supernode *node,
|
||||||
file descriptor i.e the first argument. */
|
file descriptor i.e the first argument. */
|
||||||
if (lhs)
|
if (lhs)
|
||||||
{
|
{
|
||||||
if (is_constant_fd_p (state_arg_1))
|
if (is_constant_fd_p (state_arg_1) || state_arg_1 == m_start)
|
||||||
sm_ctxt->set_next_state (stmt, lhs, m_unchecked_read_write);
|
sm_ctxt->set_next_state (stmt, lhs, m_unchecked_read_write);
|
||||||
else
|
else
|
||||||
sm_ctxt->set_next_state (stmt, lhs,
|
sm_ctxt->set_next_state (stmt, lhs,
|
||||||
|
|
|
@ -220,4 +220,29 @@ test_19 (const char *path, void *buf)
|
||||||
close (fd);
|
close (fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int m;
|
||||||
|
|
||||||
|
void
|
||||||
|
test_20 ()
|
||||||
|
{
|
||||||
|
int fd = dup (m);
|
||||||
|
close (fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
test_21 ()
|
||||||
|
{
|
||||||
|
int fd = dup2 (m, 1);
|
||||||
|
close (fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
test_22 (int flags)
|
||||||
|
{
|
||||||
|
int fd = dup3 (m, 1, flags);
|
||||||
|
close (fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,6 @@ test_1 ()
|
||||||
{
|
{
|
||||||
int m;
|
int m;
|
||||||
return dup (m); /* { dg-warning "use of uninitialized value 'm'" "uninit" } */
|
return dup (m); /* { dg-warning "use of uninitialized value 'm'" "uninit" } */
|
||||||
/* { dg-bogus "'dup' on possibly invalid file descriptor 'm'" "invalid fd false +ve" { xfail *-*-* } .-1 } */
|
|
||||||
/* XFAIL: probably covered by fix for PR analyzer/106551. */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
Loading…
Reference in New Issue