summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu@cvs.openbsd.org>2014-07-12 16:32:59 +0000
committerMatthieu Herrb <matthieu@cvs.openbsd.org>2014-07-12 16:32:59 +0000
commit15c97eab008c239f9e123ef85a09cddf0c4eae8a (patch)
tree15686d276d150855afc8f2c4344d78ee83d7c94a
parentca921f4864416b3bcc7405f0783fe98dee25b61b (diff)
Eliminate strcpy() and sprintf() in auxcpp. ok deraadt@
-rw-r--r--libexec/auxcpp/cpp.c13
-rw-r--r--libexec/auxcpp/macro.c9
-rw-r--r--libexec/auxcpp/tune.h6
3 files changed, 13 insertions, 15 deletions
diff --git a/libexec/auxcpp/cpp.c b/libexec/auxcpp/cpp.c
index f79abd5e994..ae407b64423 100644
--- a/libexec/auxcpp/cpp.c
+++ b/libexec/auxcpp/cpp.c
@@ -546,12 +546,13 @@ static void print_line_info(struct lexer_state *ls, unsigned long flags)
char *fn = current_long_filename ?
current_long_filename : current_filename;
char *b, *d;
+ size_t len = 50 + strlen(fn);
- b = getmem(50 + strlen(fn));
+ b = getmem(len);
if (flags & GCC_LINE_NUM) {
- sprintf(b, "# %ld \"%s\"\n", ls->line, fn);
+ snprintf(b, len, "# %ld \"%s\"\n", ls->line, fn);
} else {
- sprintf(b, "#line %ld \"%s\"\n", ls->line, fn);
+ snprintf(b, len, "#line %ld \"%s\"\n", ls->line, fn);
}
for (d = b; *d; d ++) put_char(ls, (unsigned char)(*d));
freemem(b);
@@ -1357,15 +1358,17 @@ include_macro2:
string_fname = 1;
} else if (left_angle(tf2.t[x].type) && right_angle(tf2.t[y].type)) {
int i, j;
+ size_t len;
if (ls->flags & WARN_ANNOYING) warning(l, "reconstruction "
"of <foo> in #include");
for (j = 0, i = x; i <= y; i ++) if (!ttWHI(tf2.t[i].type))
j += strlen(tname(tf2.t[i]));
- fname = getmem(j + 1);
+ len = j + 1;
+ fname = getmem(len);
for (j = 0, i = x; i <= y; i ++) {
if (ttWHI(tf2.t[i].type)) continue;
- strcpy(fname + j, tname(tf2.t[i]));
+ strlcpy(fname + j, tname(tf2.t[i]), len - j);
j += strlen(tname(tf2.t[i]));
}
*(fname + j - 1) = 0;
diff --git a/libexec/auxcpp/macro.c b/libexec/auxcpp/macro.c
index 5b9540c67c2..4aecfa16ce3 100644
--- a/libexec/auxcpp/macro.c
+++ b/libexec/auxcpp/macro.c
@@ -976,7 +976,7 @@ static inline char *stringify_string(char *x)
*/
static char *stringify(struct token_fifo *tf)
{
- size_t tlen;
+ size_t tlen, len;
size_t i;
char *x, *y;
@@ -984,11 +984,12 @@ static char *stringify(struct token_fifo *tf)
if (tf->t[i].type < CPPERR && tf->t[i].type != OPT_NONE)
tlen += strlen(token_name(tf->t + i));
if (tlen == 0) return sdup("\"\"");
- x = getmem(tlen + 1);
+ len = tlen + 1;
+ x = getmem(len);
for (tlen = 0, i = 0; i < tf->nt; i ++) {
if (tf->t[i].type >= CPPERR || tf->t[i].type == OPT_NONE)
continue;
- strcpy(x + tlen, token_name(tf->t + i));
+ strlcpy(x + tlen, token_name(tf->t + i), len - tlen);
tlen += strlen(token_name(tf->t + i));
}
/* no need to add a trailing 0: strcpy() did that (and the string
@@ -1062,7 +1063,7 @@ int substitute_macro(struct lexer_state *ls, struct macro *m,
case MAC_LINE:
t.type = NUMBER;
t.line = l;
- sprintf(buf, "%ld", l);
+ snprintf(buf, sizeof(buf), "%ld", l);
t.name = buf;
print_space(ls);
print_token(ls, &t, 0);
diff --git a/libexec/auxcpp/tune.h b/libexec/auxcpp/tune.h
index e4afc31f9c4..b38d3fc82b9 100644
--- a/libexec/auxcpp/tune.h
+++ b/libexec/auxcpp/tune.h
@@ -382,12 +382,6 @@
#undef UCPP_MMAP
#endif
-#if defined(UCPP_MMAP) || defined(POSIX_JMP)
-#ifndef _POSIX_SOURCE
-#define _POSIX_SOURCE 1
-#endif
-#endif
-
/*
* C90 does not know about the "inline" keyword, but C99 does know,
* and some C90 compilers know it as an extension. This part detects