[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)

2024-05-10 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat updated https://github.com/llvm/llvm-project/pull/91531 From 07dc4dd5c60c8a04637cce686b379e195deb5b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Wed, 8 May 2024 20:01:57 +0200 Subject: [PATCH 1/3] [analyzer] Refactor recognition of the errno

[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)

2024-05-10 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat updated https://github.com/llvm/llvm-project/pull/91531 From 07dc4dd5c60c8a04637cce686b379e195deb5b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Wed, 8 May 2024 20:01:57 +0200 Subject: [PATCH 1/4] [analyzer] Refactor recognition of the errno

[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)

2024-05-10 Thread Donát Nagy via cfe-commits
@@ -136,53 +100,48 @@ void ErrnoModeling::checkBeginFunction(CheckerContext &C) const { ASTContext &ACtx = C.getASTContext(); ProgramStateRef State = C.getState(); - if (const auto *ErrnoVar = dyn_cast_or_null(ErrnoDecl)) { -// There is an external 'errno' variable.

[clang] [clang][analyzer] Check for label location bindings in `DereferenceChecker` (PR #91119)

2024-05-13 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. LGTM. My only significant observation is that `BugReporterVisitors.cpp` must be cleaned up eventually, as it is currently a heap of ad-hoc special cases. However, it would be unreasonable to wait for that difficult cleanup with this sim

[clang] [clang][analyzer] Add checker 'security.SetgidSetuidOrder'. (PR #91445)

2024-05-13 Thread Donát Nagy via cfe-commits
@@ -0,0 +1,197 @@ +//===-- SetgidSetuidOrderChecker.cpp - check privilege revocation calls ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Ap

[clang] [clang][analyzer] Add checker 'security.SetgidSetuidOrder'. (PR #91445)

2024-05-13 Thread Donát Nagy via cfe-commits
@@ -0,0 +1,170 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,security.SetgidSetuidOrder -verify %s + +#include "Inputs/system-header-simulator-setgid-setuid.h" + +void correct_order() { + if (setgid(getgid()) == -1) +return; + if (setuid(getuid()) == -1) +return

[clang] [clang][analyzer] Add checker 'security.SetgidSetuidOrder'. (PR #91445)

2024-05-13 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/91445 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][analyzer] Add checker 'security.SetgidSetuidOrder'. (PR #91445)

2024-05-13 Thread Donát Nagy via cfe-commits
@@ -0,0 +1,196 @@ +//===-- SetgidSetuidOrderChecker.cpp - check privilege revocation calls ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Ap

[clang] [clang][analyzer] Add checker 'security.SetgidSetuidOrder'. (PR #91445)

2024-05-13 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: Thanks for updating your commit! Now there are only two remaining issues and they are both very minor (marked by inline comments: renaming `CallExpr *CE` and explaining the reason why "trying to set the gid again" appears as a special case in the SEI-CER

[clang] [clang][analyzer] Check for label location bindings in `DereferenceChecker` (PR #91119)

2024-05-13 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat closed https://github.com/llvm/llvm-project/pull/91119 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)

2024-05-13 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat updated https://github.com/llvm/llvm-project/pull/91531 From 07dc4dd5c60c8a04637cce686b379e195deb5b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Wed, 8 May 2024 20:01:57 +0200 Subject: [PATCH 1/5] [analyzer] Refactor recognition of the errno

[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)

2024-05-13 Thread Donát Nagy via cfe-commits
@@ -136,53 +100,48 @@ void ErrnoModeling::checkBeginFunction(CheckerContext &C) const { ASTContext &ACtx = C.getASTContext(); ProgramStateRef State = C.getState(); - if (const auto *ErrnoVar = dyn_cast_or_null(ErrnoDecl)) { -// There is an external 'errno' variable.

[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)

2024-05-14 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat updated https://github.com/llvm/llvm-project/pull/91531 From 07dc4dd5c60c8a04637cce686b379e195deb5b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Wed, 8 May 2024 20:01:57 +0200 Subject: [PATCH 1/6] [analyzer] Refactor recognition of the errno

[clang] [analyzer] Clean up list of taint propagation functions (PR #91635)

2024-05-14 Thread Donát Nagy via cfe-commits
@@ -572,196 +570,236 @@ void GenericTaintChecker::initTaintRules(CheckerContext &C) const { std::vector>; using TR = GenericTaintRule; - const Builtin::Context &BI = C.getASTContext().BuiltinInfo; - RulesConstructionTy GlobalCRules{ // Sources - {{{"fd

[clang] [analyzer] Clean up list of taint propagation functions (PR #91635)

2024-05-14 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat updated https://github.com/llvm/llvm-project/pull/91635 From 57ad704c30866a7d85f43b016583675e70de8531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Thu, 9 May 2024 18:32:57 +0200 Subject: [PATCH 1/2] [analyzer] Clean up list of taint propagation

[clang] [analyzer] Clean up list of taint propagation functions (PR #91635)

2024-05-14 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/91635 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Variant checker bindings (PR #87886)

2024-05-14 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: Some additional remarks. https://github.com/llvm/llvm-project/pull/87886 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Variant checker bindings (PR #87886)

2024-05-14 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/87886 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Variant checker bindings (PR #87886)

2024-05-14 Thread Donát Nagy via cfe-commits
@@ -206,23 +221,42 @@ class StdVariantChecker : public Checker { if (!ThisMemRegion) return; +// Get the first type alternative of the std::variant instance. +assert((ThisSVal.getType(C.getASTContext())->isPointerType() || +ThisSVal.getType(C.getA

[clang] [analyzer] Variant checker bindings (PR #87886)

2024-05-14 Thread Donát Nagy via cfe-commits
@@ -37,6 +43,19 @@ static SVal conjureOffsetSymbolOnLocation( return Symbol; } +// Update the SVal bound to the Cast expression with the SVal +// bound to the casted expression +static ProgramStateRef updateStateAfterSimpleCast(StmtNodeBuilder& Bldr, NagyDon

[clang] [analyzer] Variant checker bindings (PR #87886)

2024-05-14 Thread Donát Nagy via cfe-commits
@@ -355,4 +356,38 @@ void nonInlineFunctionCallPtr() { char c = std::get (v); // no-warning (void)a; (void)c; -} \ No newline at end of file +} + +//// +// std::swap for std::variant +//--

[clang] [analyzer] Variant checker bindings (PR #87886)

2024-05-14 Thread Donát Nagy via cfe-commits
@@ -681,6 +681,37 @@ ExprEngine::processRegionChanges(ProgramStateRef state, LCtx, Call); } +ProgramStateRef +ExprEngine::handleCastingBeforeEvalCall(ExplodedNode *Pred, const Expr *Ex, +

[clang] [analyzer] Variant checker bindings (PR #87886)

2024-05-14 Thread Donát Nagy via cfe-commits
@@ -602,6 +619,37 @@ void ExprEngine::VisitDeclStmt(const DeclStmt *DS, ExplodedNode *Pred, ExplodedNode *UpdatedN = N; SVal InitVal = state->getSVal(InitEx, LC); + // The call expression to which we have bound something is hidden behind + // an implicit

[clang] [analyzer] Variant checker bindings (PR #87886)

2024-05-14 Thread Donát Nagy via cfe-commits
@@ -51,27 +47,29 @@ removeInformationStoredForDeadInstances(const CallEvent &Call, } template -void handleConstructorAndAssignment(const CallEvent &Call, CheckerContext &C, +bool handleConstructorAndAssignment(const CallEvent &Call, CheckerContext &C,

[clang] [analyzer] Variant checker bindings (PR #87886)

2024-05-14 Thread Donát Nagy via cfe-commits
@@ -37,6 +43,19 @@ static SVal conjureOffsetSymbolOnLocation( return Symbol; } +// Update the SVal bound to the Cast expression with the SVal +// bound to the casted expression +static ProgramStateRef updateStateAfterSimpleCast(StmtNodeBuilder& Bldr, +

[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)

2024-05-15 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat closed https://github.com/llvm/llvm-project/pull/91531 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [lldb] [llvm] [openmp] [polly] fix(python): fix comparison to True/False (PR #91858)

2024-05-15 Thread Donát Nagy via cfe-commits
NagyDonat wrote: The main problem with comparison to `True`/`False` is that it's completely redundant when the variable is _guaranteed to be boolean_. However, if a variable may contain either a boolean or something else, it's reasonable to compare it with `True` or `False`. For the operator

[clang] [analyzer] Clean up list of taint propagation functions (PR #91635)

2024-05-16 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat closed https://github.com/llvm/llvm-project/pull/91635 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer][NFC] Require explicit matching mode for CallDescriptions (PR #92454)

2024-05-16 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat created https://github.com/llvm/llvm-project/pull/92454 This commit deletes the "simple" constructor of `CallDescription` which did not require a `CallDescription::Mode` argument and always used the "wildcard" mode `CDM::Unspecified`. A few months ago, this vague

[clang] [analyzer][NFC] Require explicit matching mode for CallDescriptions (PR #92454)

2024-05-17 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat closed https://github.com/llvm/llvm-project/pull/92454 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Adding taint analysis capability to unix.Malloc checker (PR #92420)

2024-05-17 Thread Donát Nagy via cfe-commits
NagyDonat wrote: > I think the error node needs to be non-fatal. Good point, I completely agree. > For these applications it's more important to catch cases where malloc size > and index used for access are coming from "different sources", eg. one is > tainted and another isn't, doesn't matter

[clang] [clang][analyzer] Move checker alpha.security.cert.pos.34c into security.PutenvWithAuto (PR #92424)

2024-05-17 Thread Donát Nagy via cfe-commits
@@ -1032,11 +1037,6 @@ let ParentPackage = ENV in { let ParentPackage = POSAlpha in { NagyDonat wrote: Please delete the packages that will no longer contain any checkers after this change. (As it's a bad naming scheme, they shouldn't be repopulated later.)

[clang] [clang][analyzer] Move checker alpha.security.cert.pos.34c into security.PutenvWithAuto (PR #92424)

2024-05-17 Thread Donát Nagy via cfe-commits
@@ -1179,6 +1179,54 @@ security.insecureAPI.DeprecatedOrUnsafeBufferHandling (C) strncpy(buf, "a", 1); // warn } +.. _security-putenv-with-auto: + +security.PutenvWithAuto +""" +Finds calls to the ``putenv`` function which pass a pointer to an automatic

[clang] [clang][analyzer] Move checker alpha.security.cert.pos.34c into security.PutenvWithAuto (PR #92424)

2024-05-17 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: Thanks for bringing this checker out of alpha! I like the new name and I agree that the old `Limitations` section was incorrect; and I have some minor suggestions in inline comments. I'd also ask for running this checker on some open source projects; but

[clang] [clang][analyzer] Move checker alpha.security.cert.pos.34c into security.PutenvWithAuto (PR #92424)

2024-05-17 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/92424 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][analyzer] Move checker alpha.security.cert.pos.34c into security.PutenvWithAuto (PR #92424)

2024-05-17 Thread Donát Nagy via cfe-commits
@@ -1179,6 +1179,54 @@ security.insecureAPI.DeprecatedOrUnsafeBufferHandling (C) strncpy(buf, "a", 1); // warn } +.. _security-putenv-with-auto: + +security.PutenvWithAuto +""" +Finds calls to the ``putenv`` function which pass a pointer to an automatic

[clang] [clang][analyzer] Move checker alpha.security.cert.pos.34c into security.PutenvWithAuto (PR #92424)

2024-05-17 Thread Donát Nagy via cfe-commits
@@ -0,0 +1,66 @@ +// RUN: %clang_analyze_cc1 \ +// RUN: -analyzer-checker=security.PutenvWithAuto \ +// RUN: -verify %s + +#include "Inputs/system-header-simulator.h" +void free(void *); +void *malloc(size_t); +int putenv(char *); +int snprintf(char *, size_t, const char *, ...)

[clang] [clang][analyzer] Move checker alpha.security.cert.pos.34c into security.PutenvWithAuto (PR #92424)

2024-05-21 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. LGTM, feel free to merge this. As @steakhal said, ensure that the PR title/description and the commit message all reflect the actual changes that you're commiting. https://github.com/llvm/llvm-project/pull/92424 _

[clang-tools-extra] [clang-tidy][NFCI] Simplify bugprone-sizeof-expression (PR #93024)

2024-05-22 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat created https://github.com/llvm/llvm-project/pull/93024 This commit eliminates a redundant matcher subexpression from the implementation of the "sizeof-pointer-to-aggregate" part of the clang-tidy check `bugprone-sizeof-expression`. I'm fairly certain that anythin

[clang-tools-extra] [clang-tidy][NFCI] Simplify bugprone-sizeof-expression (PR #93024)

2024-05-22 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat updated https://github.com/llvm/llvm-project/pull/93024 From b7fb1707601c73bd53b6ac810cd39a94f5b3cd53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Wed, 22 May 2024 13:45:13 +0200 Subject: [PATCH 1/3] [clang-tidy][NFCI] Simplify bugprone-sizeof-

[clang-tools-extra] [clang-tidy][NFCI] Simplify bugprone-sizeof-expression (PR #93024)

2024-05-22 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat closed https://github.com/llvm/llvm-project/pull/93024 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][ASTImporter] Fix possible crash "given incorrect InsertPos for specialization". (PR #89887)

2024-05-23 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. This seems to be a reasonable and straightforward improvement which rules out a hard-to test corner case. I think it's acceptable to merge this as it is now, because crafting a testcase would require a disproportionate amount of work. ht

[clang] [analyzer] Adding taint analysis capability to unix.Malloc checker (PR #92420)

2024-05-27 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/92420 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Adding taint analysis capability to unix.Malloc checker (PR #92420)

2024-05-27 Thread Donát Nagy via cfe-commits
@@ -599,7 +599,47 @@ Warns when a nullable pointer is returned from a function that has _Nonnull retu optin ^ -Checkers for portability, performance or coding style specific rules. +Checkers for portability, performance, optional security and coding style specific rules.

[clang] [analyzer] Adding taint analysis capability to unix.Malloc checker (PR #92420)

2024-05-27 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: Oops, I noticed that I had some minor review commits that were left in a "Pending" state for at least a week. Anyway, I'm publishing them now. https://github.com/llvm/llvm-project/pull/92420 ___ cfe-commits mail

[clang] [analyzer] Adding taint analysis capability to unix.Malloc checker (PR #92420)

2024-05-27 Thread Donát Nagy via cfe-commits
@@ -36,6 +36,8 @@ def CoreAlpha : Package<"core">, ParentPackage; // Note: OptIn is *not* intended for checkers that are too noisy to be on by // default. Such checkers belong in the alpha package. def OptIn : Package<"optin">; +def TaintOptIn : Package<"taint">, ParentPackage;

[clang] [analyzer] Adding taint analysis capability to unix.Malloc checker (PR #92420)

2024-05-27 Thread Donát Nagy via cfe-commits
@@ -452,6 +454,7 @@ def EnumCastOutOfRangeChecker : Checker<"EnumCastOutOfRange">, } // end "optin.core" + NagyDonat wrote: Remove this irrelevant empty line. https://github.com/llvm/llvm-project/pull/92420 ___ c

[clang] [analyzer] Adding taint analysis capability to unix.Malloc checker (PR #92420)

2024-05-27 Thread Donát Nagy via cfe-commits
@@ -625,6 +628,16 @@ def BlockInCriticalSectionChecker : Checker<"BlockInCriticalSection">, } // end "alpha.unix" +let ParentPackage = TaintOptIn in { NagyDonat wrote: Is this the right place for this? I'd guess that this should be placed next to other `op

[clang] [analyzer] Adding taint analysis capability to unix.Malloc checker (PR #92420)

2024-05-27 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/92420 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Refine invalidation caused by `fread` (PR #93408)

2024-05-27 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/93408 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Refine invalidation caused by `fread` (PR #93408)

2024-05-27 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: Thanks for publishing this commit, it's a nice refinement of the modelling capabilities, and mostly LGTM. In the inline comments I added some very minor remarks and one question about the handling of a `fread` that reads into the beginning of an array re

[clang] [analyzer] Refine invalidation caused by `fread` (PR #93408)

2024-05-27 Thread Donát Nagy via cfe-commits
@@ -717,18 +717,71 @@ const ExplodedNode *StreamChecker::getAcquisitionSite(const ExplodedNode *N, return nullptr; } +/// Invalidate only the requested elements instead of the whole buffer. +/// This is basically a refinement of the more generic 'escapeArgs' or +/// the pla

[clang] [analyzer] Refine invalidation caused by `fread` (PR #93408)

2024-05-27 Thread Donát Nagy via cfe-commits
@@ -0,0 +1,328 @@ +// RUN: %clang_analyze_cc1 -verify %s \ +// RUN: -analyzer-checker=core,unix.Stream,alpha.security.taint \ +// RUN: -analyzer-checker=debug.ExprInspection + +#define EOF (-1) + +extern "C" { +typedef __typeof(sizeof(int)) size_t; +typedef struct _FILE FILE;

[clang] [analyzer] Refine invalidation caused by `fread` (PR #93408)

2024-05-27 Thread Donát Nagy via cfe-commits
@@ -937,8 +990,21 @@ void StreamChecker::evalFreadFwrite(const FnDescription *Desc, // At read, invalidate the buffer in any case of error or success, // except if EOF was already present. - if (IsFread && !E.isStreamEof()) -State = escapeArgs(State, C, Call, {0}); +

[clang] [analyzer] Refine invalidation caused by `fread` (PR #93408)

2024-05-27 Thread Donát Nagy via cfe-commits
@@ -717,18 +717,71 @@ const ExplodedNode *StreamChecker::getAcquisitionSite(const ExplodedNode *N, return nullptr; } +/// Invalidate only the requested elements instead of the whole buffer. +/// This is basically a refinement of the more generic 'escapeArgs' or +/// the pla

[clang] [analyzer] Refine invalidation caused by `fread` (PR #93408)

2024-05-27 Thread Donát Nagy via cfe-commits
@@ -0,0 +1,328 @@ +// RUN: %clang_analyze_cc1 -verify %s \ +// RUN: -analyzer-checker=core,unix.Stream,alpha.security.taint \ +// RUN: -analyzer-checker=debug.ExprInspection + +#define EOF (-1) + +extern "C" { +typedef __typeof(sizeof(int)) size_t; +typedef struct _FILE FILE;

[clang] [analyzer] Refine invalidation caused by `fread` (PR #93408)

2024-05-27 Thread Donát Nagy via cfe-commits
@@ -0,0 +1,328 @@ +// RUN: %clang_analyze_cc1 -verify %s \ +// RUN: -analyzer-checker=core,unix.Stream,alpha.security.taint \ +// RUN: -analyzer-checker=debug.ExprInspection + +#define EOF (-1) + +extern "C" { +typedef __typeof(sizeof(int)) size_t; +typedef struct _FILE FILE;

[clang] [analyzer] Refine invalidation caused by `fread` (PR #93408)

2024-05-27 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/93408 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Refine invalidation caused by `fread` (PR #93408)

2024-05-27 Thread Donát Nagy via cfe-commits
@@ -717,18 +717,71 @@ const ExplodedNode *StreamChecker::getAcquisitionSite(const ExplodedNode *N, return nullptr; } +/// Invalidate only the requested elements instead of the whole buffer. +/// This is basically a refinement of the more generic 'escapeArgs' or +/// the pla

[clang] [analyzer] Adding taint analysis capability to unix.Malloc checker (PR #92420)

2024-05-27 Thread Donát Nagy via cfe-commits
@@ -1730,6 +1721,21 @@ def UnixAPIPortabilityChecker : Checker<"UnixAPI">, } // end optin.portability + +//===--===// +// Taint checkers. +//===

[clang] [analyzer] Adding taint analysis capability to unix.Malloc checker (PR #92420)

2024-05-27 Thread Donát Nagy via cfe-commits
NagyDonat wrote: > Have you considered applying the same heuristic to C++ array new allocations? Actually, I'm almost certain that this patch already affects the C++ array new allocations, because `MallocMemAux` is called from the callback which handles the array new operator. @dkrupp Please

[clang] [clang][analyzer] Improve PointerSubChecker (PR #96501)

2024-08-01 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. LGTM, thanks for the updates! https://github.com/llvm/llvm-project/pull/96501 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Restore recognition of mutex methods (PR #101511)

2024-08-01 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat created https://github.com/llvm/llvm-project/pull/101511 Before commit 705788c the checker alpha.unix.BlockInCriticalSection "recognized" the methods `std::mutex::lock` and `std::mutex::unlock` with an extremely trivial check that accepted any function (or method)

[clang] [analyzer] Restore recognition of mutex methods (PR #101511)

2024-08-02 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat updated https://github.com/llvm/llvm-project/pull/101511 From 8700f803c5191e5bb266797e0d130ea27776101f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Thu, 1 Aug 2024 18:07:53 +0200 Subject: [PATCH 1/2] [analyzer] Restore recognition of mutex meth

[clang] [analyzer] Restore recognition of mutex methods (PR #101511)

2024-08-02 Thread Donát Nagy via cfe-commits
NagyDonat wrote: > Let's merge this, and backport it into clang-19. I'll deal with that. Thanks! https://github.com/llvm/llvm-project/pull/101511 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/c

[clang] [analyzer][NFC] Prune a very obsolete comment about CoreEngine (PR #101173)

2024-08-07 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat closed https://github.com/llvm/llvm-project/pull/101173 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][analyzer] Add more notes to PointerSubChecker (PR #102432)

2024-08-08 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. The change LGTM, it makes these reports somewhat easier to understand. However, note that I'll delete all array bounds checking logic from this checker when I'll bring `alpha.security.ArrayBoundsV2` out of alpha, because there is no reas

[clang] [clang][analyzer] Add more notes to PointerSubChecker (PR #102432)

2024-08-08 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/102432 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][analyzer] Add more notes to PointerSubChecker (PR #102432)

2024-08-08 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/102432 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][analyzer] Add more notes to PointerSubChecker (PR #102432)

2024-08-08 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/102432 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][analyzer] Add more notes to PointerSubChecker (PR #102432)

2024-08-08 Thread Donát Nagy via cfe-commits
NagyDonat wrote: > If the `ArrayBoundsV2` checker is finished it should find all of the cases in > the test of `PointerSubChecker` that have out-of-bound indexing, and > including the cases where a single variable is handled like an 1-element > array? Yes, `ArrayBoundV2` will handle the cases

[clang] [analyzer][NFC] Trivial refactoring of region invalidation (PR #102456)

2024-08-08 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat created https://github.com/llvm/llvm-project/pull/102456 This commit removes `invalidateRegionsImpl()`, moving its body to `invalidateRegions(ValueList Values, ...)`, because it was a completely useless layer of indirection. Moreover I'm fixing some strange indent

[clang] [analyzer][NFC] Improve documentation of `invalidateRegion` methods (PR #102477)

2024-08-08 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat created https://github.com/llvm/llvm-project/pull/102477 ... within the classes `StoreManager` and `ProgramState` and describe the connection between the two methods. From 4faf523b8f7dc6e343082649867664b1439789de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=

[clang] [analyzer] Limit `isTainted()` by skipping complicated symbols (PR #105493)

2024-08-21 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/105493 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Limit `isTainted()` by skipping complicated symbols (PR #105493)

2024-08-21 Thread Donát Nagy via cfe-commits
@@ -459,7 +460,53 @@ unsigned radar11369570_hanging(const unsigned char *arr, int l) { longcmp(a, t, c); l -= 12; } - return 5/a; // expected-warning {{Division by a tainted value, possibly zero}} + return 5/a; // FIXME: Should be a "div by tainted" warning here.

[clang] [analyzer] Limit `isTainted()` by skipping complicated symbols (PR #105493)

2024-08-21 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. The change LGTM overall, I support this kind of mitigation. I added several cosmetic bikeshedding remarks as inline comments, but they are not important enough to block this PR. https://github.com/llvm/llvm-project/pull/105493 __

[clang] [analyzer] Limit `isTainted()` by skipping complicated symbols (PR #105493)

2024-08-21 Thread Donát Nagy via cfe-commits
@@ -256,6 +257,12 @@ std::vector taint::getTaintedSymbolsImpl(ProgramStateRef State, if (!Sym) return TaintedSymbols; + // HACK:https://discourse.llvm.org/t/rfc-make-istainted-and-complex-symbols-friends/79570 + if (const auto &Opts = State->getAnalysisManager().getA

[clang] [analyzer] Limit `isTainted()` by skipping complicated symbols (PR #105493)

2024-08-21 Thread Donát Nagy via cfe-commits
@@ -407,6 +407,11 @@ ANALYZER_OPTION( ANALYZER_OPTION(unsigned, MaxSymbolComplexity, "max-symbol-complexity", "The maximum complexity of symbolic constraint.", 35) +// HACK:https://discourse.llvm.org/t/rfc-make-istainted-and-complex-symbols-friends/79570 +// I

[clang] [analyzer][NFC] Add tests for and refactor StackAddrEscapeChecker 1/3 (PR #105652)

2024-08-22 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. Nice cleanup, I especially like the through testing. https://github.com/llvm/llvm-project/pull/105652 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailma

[clang] [analyzer] Detect leak of a stack address through output arguments 2/3 (PR #105653)

2024-08-22 Thread Donát Nagy via cfe-commits
@@ -297,20 +314,29 @@ std::optional printReferrer(const MemRegion *Referrer) { return "global"; assert(isa(Space)); return "stack"; - }(Referrer->getMemorySpace()); - - // We should really only have VarRegions here. - // Anything else is really surprising, and

[clang] [analyzer] Detect leak of a stack address through output arguments 2/3 (PR #105653)

2024-08-22 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat requested changes to this pull request. Looks good overall, but `getOriginRegion()` is a troublesome function (see inline comment for details). https://github.com/llvm/llvm-project/pull/105653 ___ cfe-commits mailing list

[clang] [analyzer] Detect leak of a stack address through output arguments 2/3 (PR #105653)

2024-08-22 Thread Donát Nagy via cfe-commits
@@ -297,20 +314,29 @@ std::optional printReferrer(const MemRegion *Referrer) { return "global"; assert(isa(Space)); return "stack"; - }(Referrer->getMemorySpace()); - - // We should really only have VarRegions here. - // Anything else is really surprising, and

[clang] [analyzer] Detect leak of a stack address through output arguments 2/3 (PR #105653)

2024-08-22 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/105653 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Detect leak of a stack address through output arguments 2/3 (PR #105653)

2024-08-23 Thread Donát Nagy via cfe-commits
@@ -297,20 +314,29 @@ std::optional printReferrer(const MemRegion *Referrer) { return "global"; assert(isa(Space)); return "stack"; - }(Referrer->getMemorySpace()); - - // We should really only have VarRegions here. - // Anything else is really surprising, and

[clang] [analyzer] Detect leak of a stack address through output arguments 2/3 (PR #105653)

2024-08-23 Thread Donát Nagy via cfe-commits
@@ -297,20 +314,29 @@ std::optional printReferrer(const MemRegion *Referrer) { return "global"; assert(isa(Space)); return "stack"; - }(Referrer->getMemorySpace()); - - // We should really only have VarRegions here. - // Anything else is really surprising, and

[clang] [analyzer] Detect leak of a stack address through output arguments 2/3 (PR #105653)

2024-08-23 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/105653 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Detect leak of a stack address through output arguments 2/3 (PR #105653)

2024-08-23 Thread Donát Nagy via cfe-commits
@@ -297,20 +314,29 @@ std::optional printReferrer(const MemRegion *Referrer) { return "global"; assert(isa(Space)); return "stack"; - }(Referrer->getMemorySpace()); - - // We should really only have VarRegions here. - // Anything else is really surprising, and

[clang] [analyzer] Detect leak of a stack address through output arguments 2/3 (PR #105653)

2024-08-23 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/105653 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Detect leak of a stack address through output arguments 2/3 (PR #105653)

2024-08-23 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/105653 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Detect leak of a stack address through output arguments 2/3 (PR #105653)

2024-08-23 Thread Donát Nagy via cfe-commits
@@ -161,3 +164,619 @@ C make1() { void test_copy_elision() { C c1 = make1(); } + +namespace leaking_via_direct_pointer { +void* returned_direct_pointer_top() { + int local = 42; + int* p = &local; + return p; // expected-warning{{associated with local variable 'local' ret

[clang] [analyzer] Detect leak of a stack address through output arguments 2/3 (PR #105653)

2024-08-23 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: Mostly LGTM and thanks for adding the "`origin_region_limitation`" test. (I added one minor remark as inline comment.) https://github.com/llvm/llvm-project/pull/105653 ___ cfe-commits mailing list cfe-commits@li

[clang] [analyzer] Detect leak of a stack address through output arguments 2/3 (PR #105653)

2024-08-23 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. Thanks for the update, I'm satisfied with this commit now. https://github.com/llvm/llvm-project/pull/105653 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/

[clang] [analyzer] Detect leaks of stack addresses via output params, indirect globals 3/3 (PR #105648)

2024-08-26 Thread Donát Nagy via cfe-commits
NagyDonat wrote: Please ping me when this commit is in a clean state that can be reviewed (e.g. updates on earlier commits are incorporated). Thanks! https://github.com/llvm/llvm-project/pull/105648 ___ cfe-commits mailing list cfe-commits@lists.llvm.

[clang] [analyzer] Report violations of the "returns_nonnull" attribute (PR #106048)

2024-08-26 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/106048 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Report violations of the "returns_nonnull" attribute (PR #106048)

2024-08-26 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: Thanks for this improvement, I'm really happy to see this! (I added some inline comments, but they are all minor and tangential.) Right now all the `nullability.*` checkers are marked as (ObjC) in [the documentation](https://clang.llvm.org/docs/analyz

[clang] [analyzer] Report violations of the "returns_nonnull" attribute (PR #106048)

2024-08-26 Thread Donát Nagy via cfe-commits
@@ -10,3 +12,42 @@ void block_arity_mismatch() { void(^b)() = ^(int a, int b) { }; b(1); // no-crash expected-warning {{Block taking 2 arguments is called with fewer (1)}} } + +int *nonnull_return_annotation_indirect() __attribute__((returns_nonnull)); +int *nonnull_retur

[clang] [analyzer] Report violations of the "returns_nonnull" attribute (PR #106048)

2024-08-26 Thread Donát Nagy via cfe-commits
@@ -1,4 +1,6 @@ -// RUN: %clang_analyze_cc1 -fblocks -analyzer-checker=core,nullability -Wno-deprecated-non-prototype -verify %s +// RUN: %clang_analyze_cc1 -fblocks -analyzer-checker=core,nullability,debug.ExprInspection -Wno-deprecated-non-prototype -verify %s ---

[clang] [analyzer] Report violations of the "returns_nonnull" attribute (PR #106048)

2024-08-26 Thread Donát Nagy via cfe-commits
@@ -10,3 +12,42 @@ void block_arity_mismatch() { void(^b)() = ^(int a, int b) { }; b(1); // no-crash expected-warning {{Block taking 2 arguments is called with fewer (1)}} } + +int *nonnull_return_annotation_indirect() __attribute__((returns_nonnull)); +int *nonnull_retur

[clang] [analyzer] Report violations of the "returns_nonnull" attribute (PR #106048)

2024-08-26 Thread Donát Nagy via cfe-commits
@@ -692,6 +692,14 @@ void NullabilityChecker::checkPreStmt(const ReturnStmt *S, NullConstraint Nullness = getNullConstraint(*RetSVal, State); Nullability RequiredNullability = getNullabilityAnnotation(RequiredRetType); + if (const auto *FunDecl = C.getLocationContext()->g

[clang] [analyzer] Detect leaks of stack addresses via output params, indirect globals 3/3 (PR #105648)

2024-08-26 Thread Donát Nagy via cfe-commits
@@ -369,24 +393,48 @@ void StackAddrEscapeChecker::checkEndFunction(const ReturnStmt *RS, const auto *ReferrerStackSpace = ReferrerMemSpace->getAs(); + if (!ReferrerStackSpace) return false; - if (ReferredMemSpace->getStackFrame() == Pop

<    1   2   3   4   5   6   7   8   9   10   >