Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

`STR34-C`: Rule improvements

Abierto
#577 0 comentarios 0 reacciones 1 asignado Ver en GitHub

@lcartey ya está trabajando en esto.

Desde el 1/5/2024.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

Difficulty-Medium false positive/false negative Impact-High Standard-CERT-C
Affected rules
  • STR34-C
Description
  • Do not consider specifiers when considering whether a type is a char type - whether a type is const, volatile etc. doesn't impact whether it's vulnerable to this bug.
  • Exclude cases where the range of the casted value does not contain negative values - this is because only negative signed char values are modified by the conversion to a larger signed integer.
  • Do not consider conversions to larger unsigned integers (they are excluded by the rule).
  • Do not report issues on platforms on which char is unsigned by default. Currently we say we want CharTypes but not UnsignedCharTypes, however that does not exclude the case where char is unsigned. I think we want the equivalent of c.getExpr().getType().(CharType).isSigned() (notwithstanding the first point in the list about specifiers)
  • Ignore implicit integer promotion conversions which occur as part of an equality or inequality comparison, where the other side of the comparison is also a signed char. In this specific case, the equality only holds if it would have held before the conversions.
  • We could also consider excluding the common pattern of (a >= 'A' && a <= ' F') and similar. These are safe as long as the two constants are within the range [0..CHAR_MAX].
  • We should also consider how to handle calls to library macros (such as tolower) which often create multiple results, which can be confusing to the user.
Example
void example_function(const char x) {
  if (x == EOF) ; // NON_COMPLIANT[FALSE_NEGATIVE] - missed because `x` is a `const char`

  if ('1' == EOF) ; // COMPLIANT[FALSE_POSITIVE] - assuming ASCII `1` can be represented by larger signed integral types, this is not a problem

  if (x == 1u) ; // Excluded from the rule by definition

  if (x == '~') ; // COMPLIANT - comparison valid - both sides have the same conversion applied
  if (x > '~') ; // NON_COMPLIANT - comparison isn't valid - `x` may be negative.
}
Lenguaje dominante
CodeQL
Estrellas
227
Forks
82
Merge medio
6 d 7 h
PR fusionados (30 d)
9

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de github/codeql-coding-standards

Todos los issues de github/codeql-coding-standards

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.