scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit ec0233d15a205f9f6bd7d3755f50badd19a0d853
parent f76494300445f6884ed10b25c7d1ebbfe5c568e0
Author: Quentin Rameau <quinq@fifth.space>
Date:   Thu,  2 Jun 2016 20:54:44 +0200

[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().

Diffstat:
Mdriver/posix/scc.c | 21+++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)

diff --git 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 @@ build(char *file) 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 @@ main(int argc, char *argv[]) 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;