odbccp32: Implement SQLGetPrivateProfileString (try 5)

Hugh McMaster hugh.mcmaster at outlook.com
Tue Jun 16 05:29:35 CDT 2015


On Sun, 14 Jun 2015 14:58:36 +1000, Alistair Leslie-Hughes wrote:
>
>+    ret = SQLGetPrivateProfileStringW(sect, entry, string, retval, cbRetBuffer, file);
>+    if(ret)
>+    {
>+        WideCharToMultiByte(CP_ACP, 0, retval, -1, RetBuffer, cbRetBuffer, NULL, NULL);
>+        RetBuffer[ret] = 0;
>+    }

If retval is null terminated, you do not need RetBuffer[ret] = 0;.

The -1 in WideCharToMultiByte means the function calculates the length of the input string, including any null terminating character. If the input string is null terminated, the output string is also null terminated. So, if this is the case, you are actually null-terminating twice and, depending on the size of cbRetBuffer, the second null termination may be out of bounds.

If retval isn't null terminated, you should use the return value of WideCharToMultiByte (the number of bytes written to RetBuffer) instead of 'ret'.
 		 	   		  


More information about the wine-devel mailing list