Commit dccd41a8 authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

kernel: Fixed regression in atom handling.

Added proper tests (local & global functions).
parent 2d0ad094
...@@ -485,12 +485,15 @@ UINT WINAPI GlobalGetAtomNameW( ATOM atom, LPWSTR buffer, INT count ) ...@@ -485,12 +485,15 @@ UINT WINAPI GlobalGetAtomNameW( ATOM atom, LPWSTR buffer, INT count )
{ {
length = min( abi->NameLength / sizeof(WCHAR), count); length = min( abi->NameLength / sizeof(WCHAR), count);
memcpy( buffer, abi->Name, length * sizeof(WCHAR) ); memcpy( buffer, abi->Name, length * sizeof(WCHAR) );
/* yes, the string will not be null terminated if the passed buffer
* is one WCHAR too small (and it's not an error)
*/
if (length < abi->NameLength / sizeof(WCHAR)) if (length < abi->NameLength / sizeof(WCHAR))
{ {
SetLastError( ERROR_MORE_DATA ); SetLastError( ERROR_MORE_DATA );
length = count; length = count;
} }
else buffer[length] = '\0'; else if (length < count) buffer[length] = '\0';
} }
return length; return length;
} }
......
...@@ -220,6 +220,21 @@ static void test_get_atom_name(void) ...@@ -220,6 +220,21 @@ static void test_get_atom_name(void)
} }
} }
memset( buf, '.', sizeof(buf) );
len = GlobalGetAtomNameA( atom, buf, 6 );
ok( len == 0, "bad length %d\n", len );
ok( !memcmp( buf, "fooba\0....", 10 ), "bad buffer contents\n");
if (unicode_OS)
{
static const WCHAR resW[] = {'f','o','o','b','a','r','.','.','.','.'};
for (len = 0; len < 10; len++) bufW[len] = '.';
SetLastError(0xdeadbeef);
len = GlobalGetAtomNameW( atom, bufW, 6 );
ok( len && GetLastError() == 0xdeadbeef, "GlobalGetAtomNameW failed\n" );
ok( len == lstrlenW(foobarW), "bad length %d\n", len );
ok( !memcmp( bufW, resW, 10*sizeof(WCHAR) ), "bad buffer contents\n" );
}
/* test string limits & overflow */ /* test string limits & overflow */
do_initA(in, "abcdefghij", 255); do_initA(in, "abcdefghij", 255);
atom = GlobalAddAtomA(in); atom = GlobalAddAtomA(in);
...@@ -428,6 +443,24 @@ static void test_local_get_atom_name(void) ...@@ -428,6 +443,24 @@ static void test_local_get_atom_name(void)
ok( !memcmp( bufW, resultW, 10*sizeof(WCHAR) ), "bad buffer contents\n" ); ok( !memcmp( bufW, resultW, 10*sizeof(WCHAR) ), "bad buffer contents\n" );
} }
/* Get the name of the atom we added above */
memset( buf, '.', sizeof(buf) );
len = GetAtomNameA( atom, buf, 6 );
ok( len == 5, "bad length %d\n", len );
ok( !memcmp( buf, "fooba\0....", 10 ), "bad buffer contents\n" );
/* Repeat, unicode-style */
if (unicode_OS)
{
WCHAR resW[] = {'f','o','o','b','a','\0','.','.','.','.'};
for (i = 0; i < 10; i++) bufW[i] = '.';
SetLastError( 0xdeadbeef );
len = GetAtomNameW( atom, bufW, 6 );
ok( len && GetLastError() == 0xdeadbeef, "GlobalGetAtomNameW failed\n" );
ok( len == 5, "bad length %d\n", len );
ok( !memcmp( bufW, resW, 10*sizeof(WCHAR) ), "bad buffer contents\n" );
}
/* Check error code returns */ /* Check error code returns */
memset(buf, '.', 10); memset(buf, '.', 10);
ok( !GetAtomNameA( atom, buf, 0 ), "succeeded\n" ); ok( !GetAtomNameA( atom, buf, 0 ), "succeeded\n" );
......
...@@ -207,6 +207,15 @@ static void test_NtAtom(void) ...@@ -207,6 +207,15 @@ static void test_NtAtom(void)
ok(!Name[3], "wrong string termination\n"); ok(!Name[3], "wrong string termination\n");
ok(Name[4] == 0x55AA, "buffer overwrite\n"); ok(Name[4] == 0x55AA, "buffer overwrite\n");
Len = lstrlenW(testAtom2) * sizeof(WCHAR);
memset(Name, '.', sizeof(Name));
res = pRtlQueryAtomInAtomTable( AtomTable, Atom2, NULL, NULL, Name, &Len );
ok(!res, "query atom %lx\n", res);
ok(Len == (lstrlenW(testAtom2) - 1) * sizeof(WCHAR), "wrong length %lu\n", Len);
ok(!memcmp(testAtom2, Name, (lstrlenW(testAtom2) - 1) * sizeof(WCHAR)), "wrong atom name\n");
ok(Name[lstrlenW(testAtom2) - 1] == '\0', "wrong char\n");
ok(Name[lstrlenW(testAtom2)] == ('.' << 8) + '.', "wrong char\n");
res = pRtlLookupAtomInAtomTable(AtomTable, testAtom2, &testAtom); res = pRtlLookupAtomInAtomTable(AtomTable, testAtom2, &testAtom);
ok(!res, "We can't find our pinned atom!! retval: %lx\n", res); ok(!res, "We can't find our pinned atom!! retval: %lx\n", res);
ok(testAtom == Atom2, "We found wrong atom!!!\n"); ok(testAtom == Atom2, "We found wrong atom!!!\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment