[hackers] [scc] [driver] check number of given parameter for overflow || Quentin Rameau
commit ec0233d15a205f9f6bd7d3755f50badd19a0d853
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Thu Jun 2 20:54:44 2016 +0200
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Thu Jun 2 20:54:44 2016 +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().
diff --git a/driver/posix/scc.c b/driver/posix/scc.c
index 6e2258f..31a56f1 100644
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
_AT_@ -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 {
_AT_@ -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)
{
_AT_@ -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;
Received on Thu Jun 02 2016 - 20:59:32 CEST
This archive was generated by hypermail 2.3.0
: Thu Jun 02 2016 - 21:00:16 CEST