[clang] [clang] Warn on umask() argument bits outside 0777 (PR #198130)
Denys Fedoryshchenko via cfe-commits
cfe-commits at lists.llvm.org
Fri May 22 11:06:32 PDT 2026
================
@@ -1490,6 +1490,49 @@ void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
<< FunctionName << DestinationStr << SourceStr);
}
+void Sema::checkFortifiedLibcArgument(FunctionDecl *FD, CallExpr *TheCall) {
+ if (TheCall->isValueDependent() || TheCall->isTypeDependent() ||
+ isConstantEvaluatedContext())
+ return;
+ if (!FD->isExternC())
+ return;
+ const IdentifierInfo *II = FD->getIdentifier();
+ if (!II)
+ return;
+
+ // umask(mode_t): warn when the constant-evaluated argument has bits set
+ // outside the file-permission mask (0777). Those bits are ignored.
+ // Require a matching system-header declaration to avoid warning on
+ // user-defined lookalikes.
+ auto AnyDeclInSystemHeader = [&](const FunctionDecl *F) {
----------------
nuclearcat wrote:
Yes, POSIX is the same as C here: umask can be forward-declared without <sys/stat.h>, and then this check goes silent.
Other fortify checks dodge this by recognizing functions via getBuiltinID, but umask isn't a builtin, so that path isn't available :(
Will make documentation changes.
https://github.com/llvm/llvm-project/pull/198130
More information about the cfe-commits
mailing list