Skip to content

Commit f3c00d8

Browse files
Make accessing va_list parameters unchecked (fix #483) (#493)
Use of VarArg parameters are assumed to be unsafe even though CheckedC will accept them with checked pointer types. If we want to support VarArgs with checked pointer types, we can remove the constraint to WILD here. We would then need to update TypeExprRewriter to rewrite the type in these expression.
1 parent e84104c commit f3c00d8

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

clang/lib/3C/ConstraintResolver.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,18 @@ CSetBkeyPair ConstraintResolver::getExprConstraintVars(Expr *E) {
639639
if (Expr *ESE = dyn_cast<Expr>(Res)) {
640640
return getExprConstraintVars(ESE);
641641
}
642+
} else if (VAArgExpr *VarArg = dyn_cast<VAArgExpr>(E)) {
643+
// Use of VarArg parameters are assumed to be unsafe even though CheckedC
644+
// will accept them with checked pointer types. If we want to support
645+
// VarArgs with checked pointer types, we can remove the constraint to
646+
// WILD here. We would then need to update TypeExprRewriter to rewrite the
647+
// type in these expression.
648+
auto *P = new PVConstraint(VarArg->getType(), nullptr, "VAArgExpr", Info,
649+
*Context);
650+
PersistentSourceLoc PL = PersistentSourceLoc::mkPSL(E, *Context);
651+
std::string Rsn = "Accessing VarArg parameter";
652+
P->constrainToWild(Info.getConstraints(), Rsn, &PL);
653+
Ret = pairWithEmptyBkey({P});
642654
} else {
643655
if (Verbose) {
644656
llvm::errs() << "WARNING! Initialization expression ignored: ";

clang/test/3C/valist.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {
2424
lua_unlock(L);
2525
return ret;
2626
}
27+
28+
void foo(int i, ...) {
29+
va_list ap;
30+
va_start(ap, i);
31+
char * c = (char*) va_arg(ap,char*);
32+
//CHECK: char * c = (char*) va_arg(ap,char*);
33+
va_end(ap);
34+
}
35+
2736
/*force output*/
2837
int *p;
2938
//CHECK: _Ptr<int> p = ((void *)0);

0 commit comments

Comments
 (0)