kernel32: Allow empty profile section and key name strings.

Consider "" a normal section, and fix calculation for zero
length section name string and key name string.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=8036
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=18099
Signed-off-by: Claudio Fontana <claudio.fontana@gmail.com>
Signed-off-by: Vijay Kiran Kamuju <infyquest@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
stable
Claudio Fontana 2019-03-22 23:49:28 +01:00 committed by Alexandre Julliard
parent 31f2a182e6
commit be678a52e1
2 changed files with 16 additions and 26 deletions

View File

@ -500,7 +500,7 @@ static BOOL PROFILE_DeleteSection( PROFILESECTION **section, LPCWSTR name )
{
while (*section)
{
if ((*section)->name[0] && !strcmpiW( (*section)->name, name ))
if (!strcmpiW( (*section)->name, name ))
{
PROFILESECTION *to_del = *section;
*section = to_del->next;
@ -524,7 +524,7 @@ static BOOL PROFILE_DeleteKey( PROFILESECTION **section,
{
while (*section)
{
if ((*section)->name[0] && !strcmpiW( (*section)->name, section_name ))
if (!strcmpiW( (*section)->name, section_name ))
{
PROFILEKEY **key = &(*section)->key;
while (*key)
@ -556,7 +556,7 @@ static void PROFILE_DeleteAllKeys( LPCWSTR section_name)
PROFILESECTION **section= &CurProfile->section;
while (*section)
{
if ((*section)->name[0] && !strcmpiW( (*section)->name, section_name ))
if (!strcmpiW( (*section)->name, section_name ))
{
PROFILEKEY **key = &(*section)->key;
while (*key)
@ -582,31 +582,28 @@ static PROFILEKEY *PROFILE_Find( PROFILESECTION **section, LPCWSTR section_name,
LPCWSTR key_name, BOOL create, BOOL create_always )
{
LPCWSTR p;
int seclen, keylen;
int seclen = 0, keylen = 0;
while (PROFILE_isspaceW(*section_name)) section_name++;
if (*section_name)
{
p = section_name + strlenW(section_name) - 1;
else
p = section_name;
while ((p > section_name) && PROFILE_isspaceW(*p)) p--;
seclen = p - section_name + 1;
while ((p > section_name) && PROFILE_isspaceW(*p)) p--;
seclen = p - section_name + 1;
}
while (PROFILE_isspaceW(*key_name)) key_name++;
if (*key_name)
{
p = key_name + strlenW(key_name) - 1;
else
p = key_name;
while ((p > key_name) && PROFILE_isspaceW(*p)) p--;
keylen = p - key_name + 1;
while ((p > key_name) && PROFILE_isspaceW(*p)) p--;
keylen = p - key_name + 1;
}
while (*section)
{
if ( ((*section)->name[0])
&& (!(strncmpiW( (*section)->name, section_name, seclen )))
&& (((*section)->name)[seclen] == '\0') )
if (!strncmpiW((*section)->name, section_name, seclen) &&
((*section)->name)[seclen] == '\0')
{
PROFILEKEY **key = &(*section)->key;
@ -873,7 +870,7 @@ static INT PROFILE_GetSection( PROFILESECTION *section, LPCWSTR section_name,
while (section)
{
if (section->name[0] && !strcmpiW( section->name, section_name ))
if (!strcmpiW( section->name, section_name ))
{
UINT oldlen = len;
for (key = section->key; key; key = key->next)
@ -988,11 +985,6 @@ static INT PROFILE_GetString( LPCWSTR section, LPCWSTR key_name,
if (!def_val) def_val = empty_strW;
if (key_name)
{
if (!key_name[0])
{
PROFILE_CopyEntry(buffer, def_val, len, TRUE);
return strlenW(buffer);
}
key = PROFILE_Find( &CurProfile->section, section, key_name, FALSE, FALSE);
PROFILE_CopyEntry( buffer, (key && key->value) ? key->value : def_val,
len, TRUE );
@ -1002,7 +994,7 @@ static INT PROFILE_GetString( LPCWSTR section, LPCWSTR key_name,
return strlenW( buffer );
}
/* no "else" here ! */
if (section && section[0])
if (section)
{
INT ret = PROFILE_GetSection(CurProfile->section, section, buffer, len, FALSE);
if (!buffer[0]) /* no luck -> def_val */

View File

@ -153,9 +153,7 @@ static void test_profile_string(void)
/* works only in unicode, ascii crashes */
ret=GetPrivateProfileStringW(sW, emptyW, emptyW, bufW, ARRAY_SIZE(bufW), TESTFILE2W);
todo_wine
ok(ret == 10, "expected 10, got %u\n", ret);
todo_wine
ok(!lstrcmpW(valnokeyW,bufW), "expected %s, got %s\n",
wine_dbgstr_w(valnokeyW), wine_dbgstr_w(bufW) );