From 3f40fcb9658f2f1c86ee04df05d47c4fdfe21f51 Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Sat, 13 Apr 2013 18:17:15 +0000 Subject: [PATCH] Fix possible buffer overflows. --- Makefile | 1 - ftepp.c | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 6d4a0ed..c72b237 100644 --- a/Makefile +++ b/Makefile @@ -150,7 +150,6 @@ SPLINTFLAGS = \ -kepttrans \ -unqualifiedtrans \ +matchanyintegral \ - -bufferoverflowhigh \ +voidabstract \ -nullassign \ -unrecog \ diff --git a/ftepp.c b/ftepp.c index 6a5e9a1..a1b5f07 100644 --- a/ftepp.c +++ b/ftepp.c @@ -124,7 +124,7 @@ char *ftepp_predef_line(lex_file *context) { char *ftepp_predef_file(lex_file *context) { size_t length = strlen(context->name) + 3; /* two quotes and a terminator */ char *value = (char*)mem_a(length); - sprintf(value, "\"%s\"", context->name); + snprintf(value, length, "\"%s\"", context->name); return value; } @@ -834,7 +834,7 @@ static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *param if (resetline && !ftepp->in_macro) { char lineno[128]; - sprintf(lineno, "\n#pragma line(%lu)\n", (unsigned long)(old_lexer->sline)); + snprintf(lineno, 128, "\n#pragma line(%lu)\n", (unsigned long)(old_lexer->sline)); ftepp_out(ftepp, lineno, false); } @@ -1800,12 +1800,12 @@ bool ftepp_init() minor[2] = '"'; } else if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_GMQCC) { ftepp_add_define(NULL, "__STD_GMQCC__"); - sprintf(major, "\"%d\"", GMQCC_VERSION_MAJOR); - sprintf(minor, "\"%d\"", GMQCC_VERSION_MINOR); + snprintf(major, 32, "\"%d\"", GMQCC_VERSION_MAJOR); + snprintf(minor, 32, "\"%d\"", GMQCC_VERSION_MINOR); } else if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_QCCX) { ftepp_add_define(NULL, "__STD_QCCX__"); - sprintf(major, "\"%d\"", GMQCC_VERSION_MAJOR); - sprintf(minor, "\"%d\"", GMQCC_VERSION_MINOR); + snprintf(major, 32, "\"%d\"", GMQCC_VERSION_MAJOR); + snprintf(minor, 32, "\"%d\"", GMQCC_VERSION_MINOR); } else if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_QCC) { ftepp_add_define(NULL, "__STD_QCC__"); /* 1.0 */ -- 2.39.2