From 51e304f10f6a184f39f1f69d2f0d52e7cd9e5347 Mon Sep 17 00:00:00 2001 From: acqn Date: Mon, 18 Sep 2023 16:44:04 +0800 Subject: [PATCH] Added check for total arguments size for variadic functions. --- src/cc65/expr.c | 4 ++++ test/err/bug2144.c | 13 +++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 test/err/bug2144.c diff --git a/src/cc65/expr.c b/src/cc65/expr.c index 47a05eca0..37af494b5 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -1035,6 +1035,10 @@ static void FunctionCall (ExprDesc* Expr) /* Parse the argument list and pass them to the called function */ ArgSize = FunctionArgList (Func, IsFastcall, Expr); + if (ArgSize > 0xFF && (Func->Flags & FD_VARIADIC) != 0) { + Error ("Total size of all arguments passed to a variadic function cannot exceed 255 bytes"); + } + /* We need the closing paren here */ ConsumeRParen (); diff --git a/test/err/bug2144.c b/test/err/bug2144.c new file mode 100644 index 000000000..eb27d672b --- /dev/null +++ b/test/err/bug2144.c @@ -0,0 +1,13 @@ +/* Bug #2144 - Maximum parameter size is not checked for variadic functions */ + +void a(...) {} + +void b() +{ + /* Argument size > 255 */ + a(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, + 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, + 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, + 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, + 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L); +}