PGresult *res;
const char *paramValues[1];
char *tmp;
+ int r = 0;
paramValues[0] = uid;
res = PQexecParams(db_conn,
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
fprintf(stderr, "SELECT failed: %s", PQerrorMessage(db_conn));
- PQclear(res);
- return -1;
- /* XXX Better error handling*/
+ r = -1;
+ goto free_mem;
}
assert(PQgetlength(res, 0, PQfnumber(res, "secret_key")) == YUBIKEY_KEY_SIZE);
stats->secret_key = ysc_memdup(
PQgetvalue(res, 0, PQfnumber(res, "secret_key")),
PQgetlength(res, 0, PQfnumber(res, "secret_key")));
+ if (stats->secret_key == NULL) {
+ r = -1;
+ goto free_mem;
+ }
stats->secret_uid = ysc_memdup(
PQgetvalue(res, 0, PQfnumber(res, "secret_uid")),
PQgetlength(res, 0, PQfnumber(res, "secret_uid")));
+ if (stats->secret_uid == NULL) {
+ r = -1;
+ goto free_mem;
+ }
tmp = PQgetvalue(res, 0, PQfnumber(res, "session_counter"));
+ assert(tmp != NULL); /* DB schema should enforce this */
stats->session_counter = ntohl(*((uint32_t *) tmp));
tmp = PQgetvalue(res, 0, PQfnumber(res, "session_use"));
+ assert(tmp != NULL); /* DB schema should enforce this */
stats->session_use = ntohl(*((uint32_t *) tmp));
stats->public_id = NULL;
+
+free_mem:
PQclear(res);
return 0;
}