Menu

#2 Bug parsing date (Windows)

open
nobody
None
5
2007-05-30
2007-05-30
Anonymous
No

The code in function srSLMGParseTIMESTAMP3164 in syslogmessage.c has some bugs when parsing the month file, at least in the C++ compiler of Visual Studio 2003.

The original code has something like:
(for parsing "mar" or "may")

case 'M':
if(*pszTS++ == 'a')
if(*pszTS++ == 'r')
pThis->iTimStampMonth = 3;
else
if(*pszTS++ == 'y')
...

The problem with this code is that the evaluation of "*pszTS++ == 'r'" increments the pszTS pointer and then the "May" month can not be parsed.

I've changed the code adding "--pszTS" in the else parts (and adding some {):

The changed "switch" code is:

switch(*pszTS++)
{
case 'J':
if(*pszTS++ == 'a')
if(*pszTS++ == 'n')
pThis->iTimStampMonth = 1;
else
return FALSE;
else
{
--pszTS;
if(*pszTS++ == 'u')
{
if(*pszTS++ == 'n')
pThis->iTimStampMonth = 6;
else
{
--pszTS;
if(*pszTS++ == 'l')
pThis->iTimStampMonth = 7;
else
return FALSE;
}
}
else
return FALSE;
}
break;
case 'F':
if(*pszTS++ == 'e')
if(*pszTS++ == 'b')
pThis->iTimStampMonth = 2;
else
return FALSE;
else
return FALSE;
break;
case 'M':
if(*pszTS++ == 'a')
if(*pszTS++ == 'r')
pThis->iTimStampMonth = 3;
else
{
--pszTS;
if(*pszTS++ == 'y')
pThis->iTimStampMonth = 5;
else
return FALSE;
}
else
return FALSE;
break;
case 'A':
if(*pszTS++ == 'p')
if(*pszTS++ == 'r')
pThis->iTimStampMonth = 4;
else
return FALSE;
else
{
--pszTS;
if(*pszTS++ == 'u')
{
if(*pszTS++ == 'g')
pThis->iTimStampMonth = 8;
else
return FALSE;
}
else
return FALSE;
}
break;
case 'S':
if(*pszTS++ == 'e')
if(*pszTS++ == 'p')
pThis->iTimStampMonth = 9;
else
return FALSE;
else
return FALSE;
break;
case 'O':
if(*pszTS++ == 'c')
if(*pszTS++ == 't')
pThis->iTimStampMonth = 10;
else
return FALSE;
else
return FALSE;
break;
case 'N':
if(*pszTS++ == 'o')
if(*pszTS++ == 'v')
pThis->iTimStampMonth = 11;
else
return FALSE;
else
return FALSE;
break;
case 'D':
if(*pszTS++ == 'e')
if(*pszTS++ == 'c')
pThis->iTimStampMonth = 12;
else
return FALSE;
else
return FALSE;
break;
default:
return FALSE;
}

===========

Best regards,

Jordi

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.