ref: 7bba9eb77e7f3fb5c47ee9457252dede76563d45
parent: 3f059be3ad0c219bbc1a8378b45c03717b28d49f
author: Quentin Rameau <quinq@fifth.space>
date: Thu Jun 2 16:54:44 EDT 2016
[driver] check number of given parameter for overflow Replace the ADDARG macro with a function addmacro(). Check that we have at least 3 slots for required arguments argv0, the filename, and a NULL pointer terminator for execvp().
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
@@ -14,7 +14,6 @@
#include "../../inc/arg.h"
#include "../../inc/cc.h"
-#define ADDARG(t, p) ((tools[t].args[++tools[t].nargs]) = (p))
#define NARGS 64
enum {
@@ -274,6 +273,16 @@
cleanup();
}
+void
+addarg(int tool, char *arg) {
+ struct tool *t = &tools[tool];
+
+ if (t->nargs >= NARGS - 3) /* 3: argv0, filename, NULL terminator */
+ die("scc: too many parameters given");
+
+ t->args[++t->nargs] = arg;
+}
+
static void
usage(void)
{
@@ -290,16 +299,16 @@
ARGBEGIN {
case 'D':
- ADDARG(CC1, "-D");
- ADDARG(CC1, EARGF(usage()));
+ addarg(CC1, "-D");
+ addarg(CC1, EARGF(usage()));
break;
case 'E':
Eflag = 1;
- ADDARG(CC1, "-E");
+ addarg(CC1, "-E");
break;
case 'I':
- ADDARG(CC1, "-I");
- ADDARG(CC1, EARGF(usage()));
+ addarg(CC1, "-I");
+ addarg(CC1, EARGF(usage()));
break;
case 'S':
Sflag = 1;