Skip to content

Commit

Permalink
Bug 1643557 - Make PK11_SetWrapKey explicitly handle being passed a n…
Browse files Browse the repository at this point in the history
…egative wrap argument, to avoid a signed-unsigned comparison. r=kjacobs

Depends on D78453

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

--HG--
extra : moz-landing-system : lando
  • Loading branch information
jswalden committed Jun 5, 2020
1 parent 0234cbd commit f385211
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/pk11wrap/pk11skey.c
Expand Up @@ -6,6 +6,8 @@
* Interfaces.
*/

#include <stddef.h>

#include "seccomon.h"
#include "secmod.h"
#include "nssilock.h"
Expand Down Expand Up @@ -401,15 +403,19 @@ void
PK11_SetWrapKey(PK11SlotInfo *slot, int wrap, PK11SymKey *wrapKey)
{
PK11_EnterSlotMonitor(slot);
if (wrap < PR_ARRAY_SIZE(slot->refKeys) &&
slot->refKeys[wrap] == CK_INVALID_HANDLE) {
/* save the handle and mechanism for the wrapping key */
/* mark the key and session as not owned by us so they don't get freed
* when the key goes way... that lets us reuse the key later */
slot->refKeys[wrap] = wrapKey->objectID;
wrapKey->owner = PR_FALSE;
wrapKey->sessionOwner = PR_FALSE;
slot->wrapMechanism = wrapKey->type;
if (wrap >= 0) {
size_t uwrap = (size_t)wrap;
if (uwrap < PR_ARRAY_SIZE(slot->refKeys) &&
slot->refKeys[uwrap] == CK_INVALID_HANDLE) {
/* save the handle and mechanism for the wrapping key */
/* mark the key and session as not owned by us so they don't get
* freed when the key goes way... that lets us reuse the key
* later */
slot->refKeys[uwrap] = wrapKey->objectID;
wrapKey->owner = PR_FALSE;
wrapKey->sessionOwner = PR_FALSE;
slot->wrapMechanism = wrapKey->type;
}
}
PK11_ExitSlotMonitor(slot);
}
Expand Down

0 comments on commit f385211

Please sign in to comment.