Skip to content

Commit ad20673

Browse files
committed
REVIEWED: TraceLog(), avoid possible buffer overflow
1 parent cf04425 commit ad20673

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/utils.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
// Defines and Macros
5555
//----------------------------------------------------------------------------------
5656
#ifndef MAX_TRACELOG_MSG_LENGTH
57-
#define MAX_TRACELOG_MSG_LENGTH 128 // Max length of one trace-log message
57+
#define MAX_TRACELOG_MSG_LENGTH 256 // Max length of one trace-log message
5858
#endif
5959

6060
//----------------------------------------------------------------------------------
@@ -145,7 +145,8 @@ void TraceLog(int logType, const char *text, ...)
145145
default: break;
146146
}
147147

148-
strcat(buffer, text);
148+
unsigned int textSize = strlen(text);
149+
memcpy(buffer + strlen(buffer), text, (textSize < (MAX_TRACELOG_MSG_LENGTH - 12))? textSize : (MAX_TRACELOG_MSG_LENGTH - 12));
149150
strcat(buffer, "\n");
150151
vprintf(buffer, args);
151152
fflush(stdout);

0 commit comments

Comments
 (0)