Bug 34981

Summary: suspicion of wrong argument passed to Windows API function
Product: Log4j - Now in Jira Reporter: Tom <tomas.zalusky>
Component: AppenderAssignee: log4j-dev <log4j-dev>
Status: RESOLVED FIXED    
Severity: minor    
Priority: P2    
Version: 1.2   
Target Milestone: ---   
Hardware: Other   
OS: Windows XP   

Description Tom 2005-05-20 10:45:10 UTC
I was enhancing the nteventlog.cpp file, the source of the native library
NTEventLogAppender.dll. I noticed following call in function regSetString:

RegSetValueEx(hkey, name, 0, REG_SZ, (LPBYTE)value, lstrlen(value));

Though it doesn't produce any error (for the present :-), it is IMHO in
contradiction with MSDN documentation, where following is said:

"If the data is of type REG_SZ, REG_EXPAND_SZ, or REG_MULTI_SZ, cbData must
include the size of the terminating null character or characters."
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/regsetvalueex.asp)

So the correct call should be
RegSetValueEx(hkey, name, 0, REG_SZ, (LPBYTE)value, lstrlen(value) + 1);

Thanks
Comment 1 Curt Arnold 2005-08-22 00:43:58 UTC
Since TCHAR can be either char or wchar_t (but likely char) in this instance, it should be

RegSetValueEx(hkey, name, 0, REG_SZ, (LPBYTE)value, lstrlen(value) + sizeof(TCHAR));
Comment 2 Mark Womack 2005-08-23 07:29:17 UTC
Applied Curt's change.  It will be in the v1.2.12rc5 build.