summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Walden <jwalden@mit.edu>2020-06-05 21:07:19 +0000
committerJeff Walden <jwalden@mit.edu>2020-06-05 21:07:19 +0000
commit8f4b20c018904c606950703659c8fd077c6bee47 (patch)
treed99a9be389c3fa82b413c82d2329b445b40b4320
parentfeff10c787fd7be8dfdb70fbb8d6e51c84eb8081 (diff)
downloadnss-hg-8f4b20c018904c606950703659c8fd077c6bee47.tar.gz
Bug 1643557 - Make pk11_MatchString accept a size_t length rather than 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
-rw-r--r--lib/pk11wrap/pk11priv.h5
-rw-r--r--lib/pk11wrap/pk11slot.c12
2 files changed, 10 insertions, 7 deletions
diff --git a/lib/pk11wrap/pk11priv.h b/lib/pk11wrap/pk11priv.h
index 8baf069cc..e9977cfdb 100644
--- a/lib/pk11wrap/pk11priv.h
+++ b/lib/pk11wrap/pk11priv.h
@@ -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"
@@ -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);
diff --git a/lib/pk11wrap/pk11slot.c b/lib/pk11wrap/pk11slot.c
index 9e641998d..162f3d2dc 100644
--- a/lib/pk11wrap/pk11slot.c
+++ b/lib/pk11wrap/pk11slot.c
@@ -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;