Blame SOURCES/coolkey-1.1.0-p15-coverity.patch

ed074c
diff -up ./src/coolkey/object.cpp.p15-coverity ./src/coolkey/object.cpp
ed074c
--- ./src/coolkey/object.cpp.p15-coverity	2015-07-06 18:02:34.604191118 -0700
ed074c
+++ ./src/coolkey/object.cpp	2015-07-06 19:06:04.432062377 -0700
ed074c
@@ -1558,7 +1558,7 @@ unsigned long GetBits(const CKYByte *ent
ed074c
    /* turn the flags into an int */
ed074c
    for (i=0; i < entrySize; i++) {
ed074c
 	CKYByte c = rev[entry[i]];
ed074c
-	bits  = bits | (c << i*8);
ed074c
+	bits  = bits | (((unsigned long)c) << (i*8));
ed074c
    }
ed074c
    return bits | bitFlag;
ed074c
 }
ed074c
@@ -1585,8 +1585,8 @@ CKYStatus PK15ObjectPath::setObjectPath(
ed074c
     if (entry == NULL) { return CKYINVALIDDATA; }
ed074c
     tagSize = entry - current;
ed074c
     current += entrySize + tagSize;
ed074c
+    if (size < (entrySize + tagSize)) { return CKYINVALIDDATA; }
ed074c
     size -= (entrySize +tagSize);
ed074c
-    if (size < 0) { return CKYINVALIDDATA; }
ed074c
     status = CKYBuffer_Replace(&path, 0, entry, entrySize);
ed074c
     if (status != CKYSUCCESS) {
ed074c
 	return status;
ed074c
@@ -1598,8 +1598,8 @@ CKYStatus PK15ObjectPath::setObjectPath(
ed074c
 	if (entry == NULL) { return CKYINVALIDDATA; }
ed074c
 	tagSize = entry - current;
ed074c
 	current += entrySize + tagSize;
ed074c
+	if (size < (entrySize + tagSize)) { return CKYINVALIDDATA; }
ed074c
 	size -= (entrySize +tagSize);
ed074c
-	if (size < 0) { return CKYINVALIDDATA; }
ed074c
 	if (entrySize > 5) { return CKYINVALIDDATA; }
ed074c
 	for (index = 0, i=0; i < entrySize; i++) {
ed074c
 	    index = (index << 8) + (unsigned int) entry[i];
ed074c
@@ -1612,8 +1612,8 @@ CKYStatus PK15ObjectPath::setObjectPath(
ed074c
 	if (entry == NULL) { return CKYINVALIDDATA; }
ed074c
 	tagSize = entry - current;
ed074c
 	current += entrySize + tagSize;
ed074c
+	if (size < (entrySize + tagSize)) { return CKYINVALIDDATA; }
ed074c
 	size -= (entrySize +tagSize);
ed074c
-	if (size < 0) { return CKYINVALIDDATA; }
ed074c
 	if (entrySize > 5) { return CKYINVALIDDATA; }
ed074c
 	for (length = 0, i=0; i < entrySize; i++) {
ed074c
 	    length = (length << 8) + (unsigned int) entry[i];
ed074c
@@ -1741,8 +1741,8 @@ set_key_type:
ed074c
     /* point current to the next section (cass attributes)  */
ed074c
     tagSize = commonAttributes - current;
ed074c
     current += commonSize + tagSize;
ed074c
+    if (currentSize < (commonSize + tagSize)) { return CKYINVALIDDATA; }
ed074c
     currentSize -= (commonSize +tagSize);
ed074c
-    if (currentSize < 0) { return CKYINVALIDDATA; }
ed074c
 
ed074c
     /* get the CKA_LABEL */
ed074c
     if (commonAttributes[0] != ASN1_UTF8_STRING) { return CKYINVALIDDATA; }
ed074c
@@ -1835,8 +1835,8 @@ PK15Object::completeCertObject(const CKY
ed074c
     /* point current to the next section (type attributes)  */
ed074c
     tagSize = commonCertAttributes - current;
ed074c
     current += commonSize + tagSize;
ed074c
+    if (currentSize < (commonSize + tagSize)) { return CKYINVALIDDATA; }
ed074c
     currentSize -= (commonSize +tagSize);
ed074c
-    if (currentSize < 0) { return CKYINVALIDDATA; }
ed074c
 
ed074c
     /* get the id */
ed074c
     if (commonCertAttributes[0] != ASN1_OCTET_STRING) { return CKYINVALIDDATA; }
ed074c
@@ -1907,8 +1907,8 @@ PK15Object::completeAuthObject(const CKY
ed074c
 	if (commonAuthAttributes == NULL) { return CKYINVALIDDATA; }
ed074c
 	tagSize = commonAuthAttributes - current;
ed074c
 	current += commonSize + tagSize;
ed074c
+	if (currentSize < (commonSize + tagSize)) { return CKYINVALIDDATA; }
ed074c
 	currentSize -= (commonSize + tagSize);
ed074c
-	if (currentSize < 0) { return CKYINVALIDDATA; }
ed074c
 	if (commonAuthAttributes[0] != ASN1_OCTET_STRING) {
ed074c
 	    return CKYINVALIDDATA;
ed074c
 	}
ed074c
@@ -1930,8 +1930,8 @@ PK15Object::completeAuthObject(const CKY
ed074c
     if (commonAuthAttributes == NULL) { return CKYINVALIDDATA; }
ed074c
     tagSize = commonAuthAttributes - current;
ed074c
     current += commonSize + tagSize;
ed074c
-    currentSize -= (commonSize +tagSize);
ed074c
-    if (currentSize < 0) { return CKYINVALIDDATA; }
ed074c
+    if (currentSize < (commonSize + tagSize)) { return CKYINVALIDDATA; }
ed074c
+    currentSize -= (commonSize + tagSize);
ed074c
     /*
ed074c
      * parse the Pin Auth Attributes 
ed074c
      *     pinFlags  BIT_STRING
ed074c
@@ -2093,8 +2093,8 @@ PK15Object::completeKeyObject(const CKYB
ed074c
     /* point current to the next section (sublcass attributes)  */
ed074c
     tagSize = commonKeyAttributes - current;
ed074c
     current += commonSize + tagSize;
ed074c
-    currentSize -= (commonSize +tagSize);
ed074c
-    if (currentSize < 0) { return CKYINVALIDDATA; }
ed074c
+    if (currentSize < (commonSize + tagSize)) { return CKYINVALIDDATA; }
ed074c
+    currentSize -= (commonSize + tagSize);
ed074c
 
ed074c
     /* get the id */
ed074c
     if (commonKeyAttributes[0] != ASN1_OCTET_STRING) { return CKYINVALIDDATA; }
ed074c
@@ -2263,8 +2263,8 @@ CKYStatus PK15Object::completePrivKeyObj
ed074c
 	/* point current to the next section (type attributes)  */
ed074c
 	tagSize = commonPrivKeyAttributes - current;
ed074c
 	current += commonSize + tagSize;
ed074c
+	if (currentSize < (commonSize + tagSize)) { return CKYINVALIDDATA; }
ed074c
 	currentSize -= (commonSize +tagSize);
ed074c
-	if (currentSize < 0) { return CKYINVALIDDATA; }
ed074c
 
ed074c
  	/* subjectName */
ed074c
 	if (commonPrivKeyAttributes[0] == ASN1_SEQUENCE) {
ed074c
@@ -2385,8 +2385,8 @@ PK15Object::completePubKeyObject(const C
ed074c
 	/* point current to the next section (type attributes)  */
ed074c
 	tagSize = commonPubKeyAttributes - current;
ed074c
 	current += commonSize + tagSize;
ed074c
-	currentSize -= (commonSize +tagSize);
ed074c
-	if (currentSize < 0) { return CKYINVALIDDATA; }
ed074c
+	if (currentSize < (commonSize + tagSize)) { return CKYINVALIDDATA; }
ed074c
+	currentSize -= (commonSize + tagSize);
ed074c
 
ed074c
  	/* subjectName */
ed074c
 	if (commonPubKeyAttributes[0] == ASN1_SEQUENCE) {
ed074c
@@ -2535,8 +2535,8 @@ PK15Object::completeRawPublicKey(const C
ed074c
     if (entry == NULL) { return CKYINVALIDDATA; }
ed074c
     tagSize = entry - current;
ed074c
     current += entrySize + tagSize;
ed074c
+    if (size < (entrySize + tagSize)) { return CKYINVALIDDATA; }
ed074c
     size -= (entrySize +tagSize);
ed074c
-    if (size < 0) { return CKYINVALIDDATA; }
ed074c
     if ((entry[0] == 0) && (entrySize > 1)) {
ed074c
 	entry++; entrySize--;
ed074c
     }
ed074c
@@ -2548,8 +2548,8 @@ PK15Object::completeRawPublicKey(const C
ed074c
     if (entry == NULL) { return CKYINVALIDDATA; }
ed074c
     tagSize = entry - current;
ed074c
     current += entrySize + tagSize;
ed074c
-    size -= (entrySize +tagSize);
ed074c
-    if (size < 0) { return CKYINVALIDDATA; }
ed074c
+    if (size < (entrySize + tagSize)) { return CKYINVALIDDATA; }
ed074c
+    size -= (entrySize + tagSize);
ed074c
     if ((entry[0] == 0) && (entrySize > 1)) {
ed074c
 	entry++; entrySize--;
ed074c
     }
ed074c
@@ -2682,11 +2682,11 @@ DEREncodedTokenInfo::DEREncodedTokenInfo
ed074c
     if (entry == NULL) return;
ed074c
     tagSize = entry - current;
ed074c
     current += tagSize + entrySize;
ed074c
+    if (size < tagSize + entrySize) return;
ed074c
     size -= tagSize + entrySize;
ed074c
     if (entrySize < 1) {
ed074c
 	version = *entry;
ed074c
     }
ed074c
-    if (size < 0) return;
ed074c
 
ed074c
     /* get the serial number */
ed074c
     if (current[0] != ASN1_OCTET_STRING) { return ; }
ed074c
@@ -2729,6 +2729,8 @@ DEREncodedTokenInfo::DEREncodedTokenInfo
ed074c
     }
ed074c
 
ed074c
     /* parsing flags */
ed074c
+#ifdef notdef
ed074c
+    /* we arn't using this right now, keep it for future reference */
ed074c
     if (current[0] == ASN1_BIT_STRING) {
ed074c
     /* recordinfo parsing would go here */
ed074c
 	unsigned long bits;
ed074c
@@ -2739,6 +2741,7 @@ DEREncodedTokenInfo::DEREncodedTokenInfo
ed074c
 	size -= tagSize + entrySize;
ed074c
 	bits = GetBits(entry, entrySize,8,2);
ed074c
     }
ed074c
+#endif
ed074c
     return;
ed074c
 }
ed074c
 
ed074c
diff -up ./src/coolkey/slot.cpp.p15-coverity ./src/coolkey/slot.cpp
ed074c
--- ./src/coolkey/slot.cpp.p15-coverity	2015-07-06 18:02:34.606191081 -0700
ed074c
+++ ./src/coolkey/slot.cpp	2015-07-06 18:02:34.610191006 -0700
ed074c
@@ -3714,7 +3714,6 @@ void
ed074c
 Slot::attemptP15Login(CK_USER_TYPE user)
ed074c
 {
ed074c
     PinCache *pinCachePtr  = userPinCache(user);
ed074c
-    const CKYBuffer *path;
ed074c
 
ed074c
     if (user == CKU_USER) {
ed074c
 	loggedIn = false;
ed074c
@@ -3729,7 +3728,6 @@ Slot::attemptP15Login(CK_USER_TYPE user)
ed074c
 			"No PKCS #15 auth object for user %d\n", user);
ed074c
     }
ed074c
 
ed074c
-    path = auth[user]->getObjectPath().getPath();
ed074c
     status = selectPath(auth[user]->getObjectPath().getPath(), &result);
ed074c
     if( status == CKYSCARDERR )  {
ed074c
 	handleConnectionError();
ed074c
diff -up ./src/libckyapplet/cky_applet.c.p15-coverity ./src/libckyapplet/cky_applet.c
ed074c
--- ./src/libckyapplet/cky_applet.c.p15-coverity	2015-07-06 18:02:34.606191081 -0700
ed074c
+++ ./src/libckyapplet/cky_applet.c	2015-07-06 18:02:34.610191006 -0700
ed074c
@@ -1361,6 +1361,9 @@ P15Applet_SignDecrypt(CKYCardConnection
ed074c
 	appendLength = length;
ed074c
     } else {
ed074c
 	ret = CKYBuffer_Reserve(&tmp, length);
ed074c
+	if (ret != CKYSUCCESS) {
ed074c
+	    goto done;
ed074c
+	}
ed074c
     }
ed074c
     CKYBuffer_AppendBuffer(&tmp, data, offset, appendLength);
ed074c
     pso.chain = 0;
ed074c
diff -up ./src/libckyapplet/cky_base.c.p15-coverity ./src/libckyapplet/cky_base.c
ed074c
--- ./src/libckyapplet/cky_base.c.p15-coverity	2015-07-06 18:02:34.607191062 -0700
ed074c
+++ ./src/libckyapplet/cky_base.c	2015-07-06 18:02:34.610191006 -0700
ed074c
@@ -736,7 +736,7 @@ CKYAPDU_SetShortReceiveLen(CKYAPDU *apdu
ed074c
     CKYStatus ret;
ed074c
 
ed074c
     if (recvlen <= CKYAPDU_MAX_DATA_LEN) {
ed074c
-	return APDU_SetReceiveLen(apdu, (CKYByte)(recvlen & 0xff));
ed074c
+	return CKYAPDU_SetReceiveLen(apdu, (CKYByte)(recvlen & 0xff));
ed074c
     }
ed074c
     ret = CKYBuffer_Resize(&apdu->apduBuf, CKYAPDU_HEADER_LEN+2);
ed074c
     if (ret != CKYSUCCESS) {