Index: nss/mozilla/security/nss/lib/softoken/sdb.c |
=================================================================== |
--- nss/mozilla/security/nss/lib/softoken/sdb.c (revision 61548) |
+++ nss/mozilla/security/nss/lib/softoken/sdb.c (working copy) |
@@ -827,51 +827,49 @@ |
goto loser; |
} |
- getStr = sqlite3_mprintf(""); |
- for (i=0; getStr && i < count; i++) { |
- if (i==0) { |
- newStr = sqlite3_mprintf("a%x", template[i].type); |
- } else { |
- newStr = sqlite3_mprintf("%s, a%x", getStr, template[i].type); |
+ for (i=0; i < count; i++) { |
+ getStr = sqlite3_mprintf("a%x", template[i].type); |
+ |
+ if (getStr == NULL) { |
+ error = CKR_HOST_MEMORY; |
+ goto loser; |
} |
+ |
+ newStr = sqlite3_mprintf(GET_ATTRIBUTE_CMD, getStr, table); |
sqlite3_free(getStr); |
- getStr = newStr; |
- } |
+ getStr = NULL; |
+ if (newStr == NULL) { |
+ error = CKR_HOST_MEMORY; |
+ goto loser; |
+ } |
- if (getStr == NULL) { |
- error = CKR_HOST_MEMORY; |
- goto loser; |
- } |
+ sqlerr = sqlite3_prepare_v2(sqlDB, newStr, -1, &stmt, NULL); |
+ sqlite3_free(newStr); |
+ newStr = NULL; |
+ if (sqlerr == SQLITE_ERROR) { |
+ template[i].ulValueLen = -1; |
+ error = CKR_ATTRIBUTE_TYPE_INVALID; |
+ continue; |
+ } else if (sqlerr != SQLITE_OK) { goto loser; } |
- newStr = sqlite3_mprintf(GET_ATTRIBUTE_CMD, getStr, table); |
- sqlite3_free(getStr); |
- getStr = NULL; |
- if (newStr == NULL) { |
- error = CKR_HOST_MEMORY; |
- goto loser; |
- } |
+ sqlerr = sqlite3_bind_int(stmt, 1, object_id); |
+ if (sqlerr != SQLITE_OK) { goto loser; } |
- sqlerr = sqlite3_prepare_v2(sqlDB, newStr, -1, &stmt, NULL); |
- if (sqlerr != SQLITE_OK) { goto loser; } |
- sqlerr = sqlite3_bind_int(stmt, 1, object_id); |
- if (sqlerr != SQLITE_OK) { goto loser; } |
- do { |
- sqlerr = sqlite3_step(stmt); |
- if (sqlerr == SQLITE_BUSY) { |
- PR_Sleep(SDB_BUSY_RETRY_TIME); |
- } |
- if (sqlerr == SQLITE_ROW) { |
- for (i=0; i < count; i++) { |
- int column = i; |
+ do { |
+ sqlerr = sqlite3_step(stmt); |
+ if (sqlerr == SQLITE_BUSY) { |
+ PR_Sleep(SDB_BUSY_RETRY_TIME); |
+ } |
+ if (sqlerr == SQLITE_ROW) { |
int blobSize; |
const char *blobData; |
- blobSize = sqlite3_column_bytes(stmt, column); |
- blobData = sqlite3_column_blob(stmt, column); |
+ blobSize = sqlite3_column_bytes(stmt, 0); |
+ blobData = sqlite3_column_blob(stmt, 0); |
if (blobData == NULL) { |
template[i].ulValueLen = -1; |
error = CKR_ATTRIBUTE_TYPE_INVALID; |
- continue; |
+ break; |
} |
/* If the blob equals our explicit NULL value, then the |
* attribute is a NULL. */ |
@@ -884,15 +882,18 @@ |
if (template[i].ulValueLen < blobSize) { |
template[i].ulValueLen = -1; |
error = CKR_BUFFER_TOO_SMALL; |
- continue; |
+ break; |
} |
PORT_Memcpy(template[i].pValue, blobData, blobSize); |
} |
template[i].ulValueLen = blobSize; |
+ found = 1; |
} |
- found = 1; |
- } |
- } while (!sdb_done(sqlerr,&retry)); |
+ } while (!sdb_done(sqlerr,&retry)); |
+ sqlite3_reset(stmt); |
+ sqlite3_finalize(stmt); |
+ stmt = NULL; |
+ } |
loser: |
/* fix up the error if necessary */ |
@@ -902,9 +903,6 @@ |
error = CKR_OBJECT_HANDLE_INVALID; |
} |
} |
- if (newStr) { |
- sqlite3_free(newStr); |
- } |
if (stmt) { |
sqlite3_reset(stmt); |