`MEM53-CPP`: False positive due to flow through `realloc`

Aberta
#420 1 comentário 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
30/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
cpp
Domínio
devtools, testing-qa

Direção de pesquisa

Comece pelos casos de teste de MEM53-CPP e pela definição de isSource da configuração de taint-tracking; em seguida, revise os pull requests vinculados referentes à alteração no fluxo de realloc. Determine como a biblioteca antiga baseada em AST trata realloc e se o cenário de teste afetado é válido; considera-se concluído quando o falso positivo for resolvido sem aceitar uma suposição insegura sobre realocar memória recém-alocada.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

Difficulty-Medium false positive/false negative Impact-Low Stardard-CERT-C++
Affected rules
  • MEM53-CPP
Description

In https://github.com/github/codeql/pull/14637 we added taint-flow through the indirection of the pointer passed to realloc to the indirection of the result. That is, flow through the following example:

int* p = ...;
*p = tainted_value;
int* q = (int*)realloc(p, 1024);
sink(*p);

this relies on the new taint-tracking library to distinguish between the result of realloc(...), and the result of what realloc(...) points to. Since the old AST-based taint-tracking library cannot do this this results in a FP in the testcases for MEM53-CPP (that we accepted on the next branch here: https://github.com/github/codeql-coding-standards/pull/419)

The query already tries to rule out realloc cases by excluding them in the definition of the taint-tracking configuration's isSource, but to get this query back to not reporting a FP here a barrier on realloc would have to be inserted.

As @jketema points out the affected test is actually really sketchy since there’s no guarantee that memory allocated with new can safely be realloc'ed. So maybe this scenario should be thought about more carefully by someone on your team.

Linguagem predominante
CodeQL
Estrelas
227
Forks
82
Merge médio
6d 7h
PRs com merge (30d)
9

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de github/codeql-coding-standards

Todas as issues de github/codeql-coding-standards

Issues semelhantes

Mais issues de DevTools

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.