Skip to content

Commit

Permalink
Bug 1643557 - Make pk11_FindObjectByTemplate accept a size_t count ra…
Browse files Browse the repository at this point in the history
…ther than a signed type to avoid internal signed-unsigned comparison warnings. r=kjacobs

Depends on D78454

Differential Revision: https://phabricator.services.mozilla.com/D78455

--HG--
extra : moz-landing-system : lando
  • Loading branch information
jswalden committed Jun 5, 2020
1 parent f385211 commit e2eeb71
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 14 deletions.
14 changes: 7 additions & 7 deletions lib/pk11wrap/pk11cert.c
Expand Up @@ -1257,9 +1257,9 @@ PK11_ImportDERCert(PK11SlotInfo *slot, SECItem *derCert,
/*
* get a certificate handle, look at the cached handle first..
*/
CK_OBJECT_HANDLE
static CK_OBJECT_HANDLE
pk11_getcerthandle(PK11SlotInfo *slot, CERTCertificate *cert,
CK_ATTRIBUTE *theTemplate, int tsize)
CK_ATTRIBUTE *theTemplate, size_t tsize)
{
CK_OBJECT_HANDLE certh;

Expand Down Expand Up @@ -1291,7 +1291,7 @@ PK11_FindPrivateKeyFromCert(PK11SlotInfo *slot, CERTCertificate *cert,
{ CKA_CLASS, NULL, 0 }
};
/* if you change the array, change the variable below as well */
int tsize = sizeof(theTemplate) / sizeof(theTemplate[0]);
const size_t tsize = sizeof(theTemplate) / sizeof(theTemplate[0]);
CK_OBJECT_HANDLE certh;
CK_OBJECT_HANDLE keyh;
CK_ATTRIBUTE *attrs = theTemplate;
Expand Down Expand Up @@ -1461,7 +1461,7 @@ PK11_ImportDERCertForKey(SECItem *derCert, char *nickname, void *wincx)

static CK_OBJECT_HANDLE
pk11_FindCertObjectByTemplate(PK11SlotInfo **slotPtr,
CK_ATTRIBUTE *searchTemplate, int count, void *wincx)
CK_ATTRIBUTE *searchTemplate, size_t count, void *wincx)
{
PK11SlotList *list;
PK11SlotListElement *le;
Expand Down Expand Up @@ -2043,7 +2043,7 @@ PK11_FindObjectForCert(CERTCertificate *cert, void *wincx, PK11SlotInfo **pSlot)
{ CKA_CLASS, NULL, 0 },
{ CKA_VALUE, NULL, 0 },
};
int templateSize = sizeof(searchTemplate) / sizeof(searchTemplate[0]);
const size_t templateSize = sizeof(searchTemplate) / sizeof(searchTemplate[0]);

attr = searchTemplate;
PK11_SETATTRS(attr, CKA_CLASS, &certClass, sizeof(certClass));
Expand Down Expand Up @@ -2642,7 +2642,7 @@ PK11_FindCertInSlot(PK11SlotInfo *slot, CERTCertificate *cert, void *wincx)
{ CKA_CLASS, NULL, 0 }
};
/* if you change the array, change the variable below as well */
int tsize = sizeof(theTemplate) / sizeof(theTemplate[0]);
const size_t tsize = sizeof(theTemplate) / sizeof(theTemplate[0]);
CK_ATTRIBUTE *attrs = theTemplate;
SECStatus rv;

Expand Down Expand Up @@ -2793,7 +2793,7 @@ PK11_GetLowLevelKeyIDForCert(PK11SlotInfo *slot,
{ CKA_CLASS, NULL, 0 }
};
/* if you change the array, change the variable below as well */
int tsize = sizeof(theTemplate) / sizeof(theTemplate[0]);
const size_t tsize = sizeof(theTemplate) / sizeof(theTemplate[0]);
CK_OBJECT_HANDLE certHandle;
CK_ATTRIBUTE *attrs = theTemplate;
PK11SlotInfo *slotRef = NULL;
Expand Down
4 changes: 3 additions & 1 deletion lib/pk11wrap/pk11kea.c
Expand Up @@ -6,6 +6,8 @@
* Interfaces.
*/

#include <stddef.h>

#include "seccomon.h"
#include "secmod.h"
#include "nssilock.h"
Expand All @@ -29,7 +31,7 @@ pk11_FindRSAPubKey(PK11SlotInfo *slot)
CK_KEY_TYPE key_type = CKK_RSA;
CK_OBJECT_CLASS class_type = CKO_PUBLIC_KEY;
CK_ATTRIBUTE theTemplate[2];
int template_count = sizeof(theTemplate) / sizeof(theTemplate[0]);
size_t template_count = sizeof(theTemplate) / sizeof(theTemplate[0]);
CK_ATTRIBUTE *attrs = theTemplate;

PK11_SETATTRS(attrs, CKA_CLASS, &class_type, sizeof(class_type));
Expand Down
2 changes: 1 addition & 1 deletion lib/pk11wrap/pk11merge.c
Expand Up @@ -464,7 +464,7 @@ pk11_mergeSecretKey(PK11SlotInfo *targetSlot, PK11SlotInfo *sourceSlot,
{ CKA_ID, NULL, 0 },
{ CKA_CLASS, NULL, 0 }
};
CK_ULONG symTemplateCount = sizeof(symTemplate) / sizeof(symTemplate[0]);
const CK_ULONG symTemplateCount = sizeof(symTemplate) / sizeof(symTemplate[0]);
CK_ATTRIBUTE symCopyTemplate[] = {
{ CKA_LABEL, NULL, 0 }
};
Expand Down
4 changes: 3 additions & 1 deletion lib/pk11wrap/pk11nobj.c
Expand Up @@ -6,6 +6,8 @@
* etc).
*/

#include <stddef.h>

#include "secport.h"
#include "seccomon.h"
#include "secmod.h"
Expand Down Expand Up @@ -552,7 +554,7 @@ PK11_FindSMimeProfile(PK11SlotInfo **slot, char *emailAddr,
{ CKA_VALUE, NULL, 0 },
};
/* if you change the array, change the variable below as well */
int tsize = sizeof(theTemplate) / sizeof(theTemplate[0]);
const size_t tsize = sizeof(theTemplate) / sizeof(theTemplate[0]);
CK_OBJECT_HANDLE smimeh = CK_INVALID_HANDLE;
CK_ATTRIBUTE *attrs = theTemplate;
CK_RV crv;
Expand Down
4 changes: 2 additions & 2 deletions lib/pk11wrap/pk11obj.c
Expand Up @@ -1808,7 +1808,7 @@ PK11_ReadRawAttributes(PLArenaPool *arena, PK11ObjectType objType, void *objSpec
* return the object handle that matches the template
*/
CK_OBJECT_HANDLE
pk11_FindObjectByTemplate(PK11SlotInfo *slot, CK_ATTRIBUTE *theTemplate, int tsize)
pk11_FindObjectByTemplate(PK11SlotInfo *slot, CK_ATTRIBUTE *theTemplate, size_t tsize)
{
CK_OBJECT_HANDLE object;
CK_RV crv = CKR_SESSION_HANDLE_INVALID;
Expand Down Expand Up @@ -2022,7 +2022,7 @@ PK11_MatchItem(PK11SlotInfo *slot, CK_OBJECT_HANDLE searchID,
};
/* if you change the array, change the variable below as well */
CK_ATTRIBUTE *keyclass = &theTemplate[1];
int tsize = sizeof(theTemplate) / sizeof(theTemplate[0]);
const size_t tsize = sizeof(theTemplate) / sizeof(theTemplate[0]);
/* if you change the array, change the variable below as well */
CK_OBJECT_HANDLE peerID;
PORTCheapArenaPool tmpArena;
Expand Down
2 changes: 1 addition & 1 deletion lib/pk11wrap/pk11skey.c
Expand Up @@ -570,7 +570,7 @@ PK11_FindFixedKey(PK11SlotInfo *slot, CK_MECHANISM_TYPE type, SECItem *keyID,
CK_ATTRIBUTE *attrs;
CK_BBOOL ckTrue = CK_TRUE;
CK_OBJECT_CLASS keyclass = CKO_SECRET_KEY;
int tsize = 0;
size_t tsize = 0;
CK_OBJECT_HANDLE key_id;

attrs = findTemp;
Expand Down
2 changes: 1 addition & 1 deletion lib/pk11wrap/secmodi.h
Expand Up @@ -93,7 +93,7 @@ CK_RV pk11_notify(CK_SESSION_HANDLE session, CK_NOTIFICATION event,
CK_VOID_PTR pdata);
void pk11_SignedToUnsigned(CK_ATTRIBUTE *attrib);
CK_OBJECT_HANDLE pk11_FindObjectByTemplate(PK11SlotInfo *slot,
CK_ATTRIBUTE *inTemplate, int tsize);
CK_ATTRIBUTE *inTemplate, size_t tsize);
CK_OBJECT_HANDLE *pk11_FindObjectsByTemplate(PK11SlotInfo *slot,
CK_ATTRIBUTE *inTemplate, size_t tsize, int *objCount);

Expand Down

0 comments on commit e2eeb71

Please sign in to comment.