COMMON: Forbid use of unsafe strcat and strcpy

This commit is contained in:
Le Philousophe 2022-09-24 10:01:34 +02:00 committed by Eugene Sandulenko
parent 6293c2b3c2
commit 9c04d72471
6 changed files with 39 additions and 2 deletions

View file

@ -64,6 +64,16 @@
#define mkdir FAKE_mkdir
#endif
#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strcpy)
#undef strcpy
#define strcpy FAKE_strcpy
#endif
#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strcat)
#undef strcat
#define strcat FAKE_strcat
#endif
// Fix compilation with MacPorts SDL 2
// It needs various (usually forbidden) symbols from time.h
#ifndef FORBIDDEN_SYMBOL_EXCEPTION_time_h
@ -255,6 +265,16 @@
#define mkdir(a,b) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
#endif
#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strcpy)
#undef strcpy
#define strcpy(a,b) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
#endif
#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strcat)
#undef strcat
#define strcat(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

@ -527,6 +527,18 @@
#define srandom(a) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
#endif
// Use Common::strcat_s or Common::strlcat in common/str.h
#ifndef FORBIDDEN_SYMBOL_EXCEPTION_strcat
#undef strcat
#define strcat(a,b) FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%*
#endif
// Use Common::strcpy_s or Common::strlcpy in common/str.h
#ifndef FORBIDDEN_SYMBOL_EXCEPTION_strcpy
#undef strcpy
#define strcpy(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,9 @@
** See Copyright Notice in lua.h
*/
#define FORBIDDEN_SYMBOL_EXCEPTION_strcpy
#define FORBIDDEN_SYMBOL_EXCEPTION_strcat
#include "common/util.h"
#define lobject_c

View file

@ -4,6 +4,8 @@
** See Copyright Notice in lua.h
*/
#define FORBIDDEN_SYMBOL_EXCEPTION_strcpy
#include "common/util.h"
#define lstrlib_c

View file

@ -1000,7 +1000,7 @@ char *scumm_strdup(const char *in) {
const size_t len = strlen(in) + 1;
char *out = (char *)malloc(len);
if (out) {
strcpy(out, in);
Common::strcpy_s(out, len, in);
}
return out;
}

View file

@ -87,7 +87,7 @@ void NORETURN_PRE error(const char *s, ...) {
buf_output[STRINGBUFLEN - 3] = '\0';
buf_output[STRINGBUFLEN - 2] = '\0';
buf_output[STRINGBUFLEN - 1] = '\0';
strcat(buf_output, "!\n");
Common::strcat_s(buf_output, "!\n");
if (g_system)
g_system->logMessage(LogMessageType::kError, buf_output);