profile.c (kernel32): API broken

Claudio Fontana claudio.fontana at gmail.com
Fri Aug 7 11:26:14 CDT 2009


Paul Vriens wrote:
> Claudio Fontana wrote:
>> On Thu, Aug 6, 2009 at 11:47 AM, Paul 
>> Vriens<paul.vriens.wine at gmail.com> wrote:
>>> Claudio Fontana wrote:
>>>> On Thu, Aug 6, 2009 at 9:38 AM, Paul Vriens<paul.vriens.wine at gmail.com>
>>>> wrote:
>>>>> Claudio Fontana wrote:
>>>>>> Just a reminder to everyone involved with profile.c:
>>>>>>
>>>>>> I have watched the git log of the somewhat recent changes to
>>>>>> kernel32/profile.c.
>>>>>>
>>>>>> The profile API does not work that way.
>>>>>>
>>>>>> The current situation is even worse than before, when the 
>>>>>> undocumented
>>>>>> empty string section and empty keys were not implemented at all.
>>>>>> The current situation leads to consistent INI file corruption when 
>>>>>> the
>>>>>> applications use the undocumented empty string section and empty 
>>>>>> keys.
>>>>>>
>>>>>> I tried to explain how the API works under Windows many times. 
>>>>>> This is
>>>>>> another casual attempt at giving you a reality check.
>>>>>> If you are interested, you can contact me for further details, or 
>>>>>> look
>>>>>> at the testcases in my last patch (search for profile.c / Claudio
>>>>>> Fontana).
>>>>>>
>>>>> Found your patch from 2006 and tested on some Windows boxes.
>>>> The testcases are more interesting than the functionality of the patch
>>>> itself.
>>>> I did the patch just to bring an application into running, it is not a
>>>> stable solution.
>>>>
>>>> The testcases are the interesting thing.
>>>>
>>>>> The WritePrivateProfileStringA crashes on Windows 2003 for both added
>>>>> tests.
>>>>> Windows 98 doesn't crash btw.
>>>>>
>>>>> Both your fixes to the implementation seem to be for reading the ini
>>>>> file.
>>>> The writing is affected too.
>>>>
>>>>> Could you rewrite the test case so it succeeds on all platforms?
>>>> I will try as soon as I get some time. However, I have no Windows 2003
>>>> to test on.
>>>>
>>>>> So, for example creating the ini file with the empty section/key
>>>>> 'manually'
>>>>> and then trying to read (again on several platforms).
>>>> Does Windows 2003 crash on _just_ the testcase? Or did you apply the
>>>> whole patch?
>>>> Also, the patch might not be compatible with the latest changes in
>>>> profile.c.
>>>>
>>>> I'll try to make the patch a little bit better, but in the meantime it
>>>> would be interesting
>>>> to know if Windows 2003 behaves differently in this situation from the
>>>> API point of view.
>>>>
>>>> Can you try just the testcase on Windows 2003 (with no other changes
>>>> added besides the new tests)?
>>> I only added the test cases (what else for a Windows box?). Both 
>>> crash on
>>> Windows 2003.
>>>
>>> I will check later (if time permits) with that newer patch you 
>>> mentioned:
>>> http://bugs2.winehq.org/attachment.cgi?id=6495
>>>
>>
>> Should it crash again, could you define 'crash' a little bit better 
>> for me?
>> Maybe running under the windows debugger (windbg) or other debugger
>> to understand where exactly the crash happens?
>>
> 
> I don't have the time to pursue this in great depth. The test crash 
> means I get a drwtsn32 when running the tests.

That is unfortunate. Not knowing what exactly happens means I am blind
and therefore less likely to be able to fix it.

> I've installed the application successfully under Windows XP

You say you have installed the application successfully under Windows
XP. By application you mean "The Spirit Engine"?
The problem does not happen on installation, but on running.
To be precise, the second run is most problematic.

On the first run the application writes the new INIs with 
WritePrivateProfileString. They look ok.

On the second run the application tries to read the values again,
and here the wine implementation fails.
The values are not found, and instead the INIs are corrupted, ie the
values are appended again.

 > but your tests crash.

This is I think the focal point, and the reason nobody cared.
The problem is, something in the test crashes under Windows > 98.
Not having access to such a system makes it hard for me to debug.

 > This either means the app is not writing the ini-files with
> the help of WritePrivateProfileStringA or it has a crash handler.

I cannot say about the "crash handler" part.

You can find the trace of the application in the bug report,
showing that indeed it is
WritePrivateProfileStringW that is called (not A).

It seems that this windows API is even fishier as I thought before.
IE, the W version of the API does not really unconditionally behave in
the UTF-16 way. So I might have assumed wrongly, and a replace of

WritePrivateProfileStringA with WritePrivateProfileStringW
is at least needed in the test, but probably the rest of the code should
be checked/changed in order to match the odd windows behaviour.

http://www.google.com/search?q=WritePrivateProfileStringW

shows an interesting result:

http://www.ureader.com/msg/147342.aspx

It seems that the function behaves in the Unicode way if the file is
already unicode, and in the A way otherwise.
This is indeed documented in

http://msdn.microsoft.com/en-us/library/ms725501%28VS.85%29.aspx

I never noticed, and I think this is currently not handled in wine.

See http://bugs2.winehq.org/attachment.cgi?id=5806
for the trace of the application calls to WritePrivateProfileStringW.

> Interestingly enough doing the same tests with 
> WritePrivateProfileStringW don't crash!?
> 

The tests ran successfully under Windows > 98? IE by replacing A with W
we get the correct behaviour? We might be on to something.


CF



More information about the wine-devel mailing list