snmpapi: Test and correct SnmpUtilOidNCmp when Oid lengths don't match.

oldstable
Juan Lang 2008-05-16 16:09:11 -07:00 committed by Alexandre Julliard
parent d88ee55e68
commit a96e118ddb
2 changed files with 15 additions and 2 deletions

View File

@ -343,17 +343,21 @@ VOID WINAPI SnmpUtilOidFree(AsnObjectIdentifier *oid)
*/
INT WINAPI SnmpUtilOidNCmp(AsnObjectIdentifier *oid1, AsnObjectIdentifier *oid2, UINT count)
{
unsigned int i;
unsigned int i, len;
TRACE("(%p, %p, %d)\n", oid1, oid2, count);
if (!oid1 || !oid2) return 0;
for (i = 0; i < count; i++)
len = min(count, oid1->idLength);
len = min(len, oid2->idLength);
for (i = 0; i < len; i++)
{
if (oid1->ids[i] > oid2->ids[i]) return 1;
if (oid1->ids[i] < oid2->ids[i]) return -1;
}
if (oid1->idLength < oid2->idLength) return -1;
if (oid1->idLength > oid2->idLength) return 1;
return 0;
}

View File

@ -321,6 +321,15 @@ static void test_SnmpUtilOidNCmp(void)
ret = SnmpUtilOidNCmp(&oid2, &oid1, 4);
ok(ret == 1, "SnmpUtilOidNCmp failed: %d\n", ret);
oid1.idLength = 3;
memcpy(oid1.ids, oid2.ids, sizeof(UINT) * 4);
ret = SnmpUtilOidNCmp(&oid1, &oid1, 4);
ok(!ret, "SnmpUtilOidNCmp failed: %d\n", ret);
ret = SnmpUtilOidNCmp(&oid2, &oid1, 4);
ok(ret == 1, "SnmpUtilOidNCmp failed: %d\n", ret);
ret = SnmpUtilOidNCmp(&oid1, &oid2, 4);
ok(ret == -1, "SnmpUtilOidNCmp failed: %d\n", ret);
}
static void test_SnmpUtilOidCmp(void)