diff options
author | peavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-07-16 13:25:03 +0000 |
---|---|---|
committer | peavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-07-16 13:25:03 +0000 |
commit | 01d29c38ca76cc9019451942806361c1a2ae163f (patch) | |
tree | e6116b4b0b30909e2385629c3752a871ed540f16 | |
parent | 110d85009eccf173c8d3705ea263a5dc5a11f885 (diff) |
Tide this up and fix possible buffer overflow. Cannot use MAXBUF since inspircd_config.h may not be generated yet.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7446 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | win/colours.h | 65 |
1 files changed, 37 insertions, 28 deletions
diff --git a/win/colours.h b/win/colours.h index 6a71d7853..3700b1dea 100644 --- a/win/colours.h +++ b/win/colours.h @@ -28,7 +28,7 @@ int printf_c(const char * format, ...) {
// Better hope we're not multithreaded, otherwise we'll have chickens crossing the road other side to get the to :P
static char message[500];
- static char temp[10];
+ static char temp[500];
int color1, color2;
/* parse arguments */
@@ -41,9 +41,9 @@ int printf_c(const char * format, ...) int t;
int c = 0;
const char * p = message;
- while(*p != 0)
+ while ( (*p) && (*p != 0) )
{
- if(*p == '\033')
+ if (*p == '\033')
{
// Escape sequence -> copy into the temp buffer, and parse the color.
p++;
@@ -56,35 +56,44 @@ int printf_c(const char * format, ...) temp[t] = 0;
p++;
- if(!_stricmp(temp, "[0"))
- {
- // Returning to normal colour.
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
- }
- else if(!_stricmp(temp, "[1"))
- {
- // White
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), TWHITE);
- }
- else if(sscanf(temp, "[%u;%u", &color1, &color2) == 2)
+
+ if (*temp == '[')
{
- switch(color2)
+ if (sscanf(temp, "[%u;%u", &color1, &color2) == 2)
{
- case 32: // Green
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY); // Yellow
- break;
+ switch(color2)
+ {
+ case 32: // Green
+ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY); // Yellow
+ break;
- default: // Unknown
- // White
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
- break;
+ default: // Unknown
+ // White
+ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
+ break;
+ }
+ }
+ else
+ {
+ switch (*(temp+1))
+ {
+ case '0':
+ // Returning to normal colour.
+ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
+ break;
+
+ case '1':
+ // White
+ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), TWHITE);
+ break;
+
+ default:
+ char message[50];
+ sprintf(message, "Unknown color code: %s", temp);
+ MessageBox(0, message, message, MB_OK);
+ break;
+ }
}
- }
- else
- {
- char message[50];
- sprintf(message, "Unknown color code: %s", temp);
- MessageBox(0, message, message, MB_OK);
}
}
|