COMMON: Forbid use of unsafe sprintf and vsprintf

This commit is contained in:
Le Philousophe 2022-10-23 15:32:54 +02:00 committed by Eugene Sandulenko
parent 43997e2911
commit 6524f7beb5
8 changed files with 38 additions and 1 deletions

View file

@ -74,6 +74,16 @@
#define strcat FAKE_strcat
#endif
#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_vsprintf)
#undef vsprintf
#define vsprintf FAKE_vsprintf
#endif
#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_sprintf)
#undef sprintf
#define sprintf FAKE_sprintf
#endif
// Fix compilation with MacPorts SDL 2
// It needs various (usually forbidden) symbols from time.h
#ifndef FORBIDDEN_SYMBOL_EXCEPTION_time_h
@ -275,6 +285,16 @@
#define strcat(a,b) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
#endif
#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_vsprintf)
#undef vsprintf
#define vsprintf(a,b,c) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
#endif
#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_sprintf)
#undef sprintf
#define sprintf(a,b,...) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
#endif
// re-forbid all those time.h symbols again (if they were forbidden)
#ifndef FORBIDDEN_SYMBOL_EXCEPTION_time_h

View file

@ -539,6 +539,18 @@
#define strcpy(a,b) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
#endif
// Use Common::vsprintf_s in common/str.h or vsnprintf
#ifndef FORBIDDEN_SYMBOL_EXCEPTION_vsprintf
#undef vsprintf
#define vsprintf(a,b,c) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
#endif
// Use Common::sprintf_s in common/str.h or snprintf
#ifndef FORBIDDEN_SYMBOL_EXCEPTION_sprintf
#undef sprintf
#define sprintf(a,b,...) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
#endif
// Use Common:scumm_stricmp in common/str.h
#ifndef FORBIDDEN_SYMBOL_EXCEPTION_stricmp
#undef stricmp

View file

@ -4,6 +4,7 @@
** See Copyright Notice in lua.h
*/
#define FORBIDDEN_SYMBOL_EXCEPTION_sprintf
#include <stdio.h>
#include <stdlib.h>

View file

@ -4,6 +4,7 @@
** See Copyright Notice in lua.h
*/
#define FORBIDDEN_SYMBOL_EXCEPTION_sprintf
#include "common/util.h"
#define llex_c

View file

@ -6,6 +6,7 @@
#define FORBIDDEN_SYMBOL_EXCEPTION_strcpy
#define FORBIDDEN_SYMBOL_EXCEPTION_strcat
#define FORBIDDEN_SYMBOL_EXCEPTION_sprintf
#include "common/util.h"

View file

@ -5,6 +5,7 @@
*/
#define FORBIDDEN_SYMBOL_EXCEPTION_strcpy
#define FORBIDDEN_SYMBOL_EXCEPTION_sprintf
#include "common/util.h"

View file

@ -4,6 +4,7 @@
** See Copyright Notice in lua.h
*/
#define FORBIDDEN_SYMBOL_EXCEPTION_sprintf
#include <stdio.h>
#include <stdlib.h>

View file

@ -39,7 +39,7 @@ class MD5TestSuite : public CxxTest::TestSuite {
Common::computeStreamMD5(stream, md5sum);
for (j = 0; j < 16; j++) {
sprintf(output + j * 2, "%02x", md5sum[j]);
snprintf(output + j * 2, 3, "%02x", md5sum[j]);
}
Common::String tmp(output);