`STR34-C`: Rule improvements
@lcartey y travaille déjà.
Depuis le 1/5/2024.
Évaluation
Cette issue n'a pas encore été évaluée.
Description
Affected rules
STR34-C
Description
- Do not consider specifiers when considering whether a type is a
chartype - whether a type isconst,volatileetc. 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
charvalues 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
charis unsigned by default. Currently we say we wantCharTypes but notUnsignedCharTypes, however that does not exclude the case wherecharis unsigned. I think we want the equivalent ofc.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.
}
- Langage dominant
- CodeQL
- Étoiles
- 227
- Forks
- 82
- Merge moyen
- 6 j 7 h
- PR mergées (30 j)
- 9
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de github/codeql-coding-standards
-
false positive/false negative Stardard-MISRA-C++
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
github/codeql-coding-standards#1172 ·
-
Difficulty-Low false positive/false negative false-negative Impact-Low Standard-MISRA-C
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
-
Difficulty-Medium false positive/false negative false-positive Impact-Medium Standard-CERT-C
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
github/codeql-coding-standards#1200 ·
-
`RULE-0-0-1`: "unreachable statement" false positives due to over-pruning of the control-flow graph Ouvertefalse positive/false negative
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
github/codeql-coding-standards#1190 ·
-
false positive/false negative
Difficulté 3/5 1-2 jours Accessibilité débutants 65/100
github/codeql-coding-standards#1175 ·