Skip to content

Commit

Permalink
Bug 1643557 - Make pk11_MatchString accept a size_t length rather tha…
Browse files Browse the repository at this point in the history
…n an int length (consistent with all callers), and reformulate its internals to avoid a signed-unsigned comparison. r=kjacobs

Depends on D78450

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

--HG--
extra : moz-landing-system : lando
  • Loading branch information
jswalden committed Jun 5, 2020
1 parent b66477b commit c203e3c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion lib/pk11wrap/pk11priv.h
Expand Up @@ -3,6 +3,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _PK11PRIV_H_
#define _PK11PRIV_H_

#include <stddef.h>

#include "plarena.h"
#include "seccomon.h"
#include "secoidt.h"
Expand Down Expand Up @@ -48,7 +51,7 @@ CK_ULONG PK11_ReadULongAttribute(PK11SlotInfo *slot, CK_OBJECT_HANDLE id,
char *PK11_MakeString(PLArenaPool *arena, char *space, char *staticSring,
int stringLen);
PRBool pk11_MatchString(const char *string,
const char *staticString, int staticStringLen);
const char *staticString, size_t staticStringLen);
int PK11_MapError(CK_RV error);
CK_SESSION_HANDLE PK11_GetRWSession(PK11SlotInfo *slot);
void PK11_RestoreROSession(PK11SlotInfo *slot, CK_SESSION_HANDLE rwsession);
Expand Down
12 changes: 6 additions & 6 deletions lib/pk11wrap/pk11slot.c
Expand Up @@ -1102,16 +1102,16 @@ PK11_MakeString(PLArenaPool *arena, char *space,
*/
PRBool
pk11_MatchString(const char *string,
const char *staticString, int staticStringLen)
const char *staticString, size_t staticStringLen)
{
int i;
size_t i = staticStringLen;

for (i = (staticStringLen - 1); i >= 0; i--) {
if (staticString[i] != ' ')
/* move i to point to the last space */
while (i > 0) {
if (staticString[i - 1] != ' ')
break;
i--;
}
/* move i to point to the last space */
i++;

if (strlen(string) == i && memcmp(string, staticString, i) == 0) {
return PR_TRUE;
Expand Down

0 comments on commit c203e3c

Please sign in to comment.