src/passwordstore/passwordstore.c
// Reads database record from *db. Assumes that the *db has *db_len bytes
// left.
// Updates *db and *db_len so that they reflect the position after the read
// record.
Reads database record from *db. Assumes that the *db has *db_len bytes
left.
Updates *db and *db_len so that they reflect the position after the read
record.
Reads database record from * db . Assumes that the * db has * db_len bytes left . Updates * db and * db_len so that they reflect the position after the read record .
static int readDbRecord(const char **db, size_t *db_len,
        struct PasswordDbRecord *rec)
{
    size_t data_len;
    rec->id_len = 0;
    rec->password_len = 0;
    if (*db_len == 0) {
        return 0;
    }
    if (*db_len < 2 * sizeof(size_t)) {
        return CORRUPTED_PASSWORD_STORE;
    }
    rec->id_len = *((size_t *) *db);
    rec->password_len = *(((size_t *) *db) + 1);
    data_len = 2 * sizeof(size_t) + rec->id_len + rec-> password_len;
    if (*db_len < data_len) {
        return CORRUPTED_PASSWORD_STORE;
    }
    *db += 2 * sizeof(size_t);
    rec->id = (char *) *db;
    *db += rec->id_len;
    rec->password = (char *) *db;
    *db += rec->password_len;
    *db_len -= data_len;
    return 0;
}
static int readDbRecord ( const char * * db , size_t * db_len , struct PasswordDbRecord * rec ) { size_t data_len ; rec -> id_len = 0 ; rec -> password_len = 0 ; if ( * db_len == 0 ) { return 0 ; } if ( * db_len < 2 * sizeof ( size_t ) ) { return CORRUPTED_PASSWORD_STORE ; } rec -> id_len = * ( ( size_t * ) * db ) ; rec -> password_len = * ( ( ( size_t * ) * db ) + 1 ) ; data_len = 2 * sizeof ( size_t ) + rec -> id_len + rec -> password_len ; if ( * db_len < data_len ) { return CORRUPTED_PASSWORD_STORE ; } * db += 2 * sizeof ( size_t ) ; rec -> id = ( char * ) * db ; * db += rec -> id_len ; rec -> password = ( char * ) * db ; * db += rec -> password_len ; * db_len -= data_len ; return 0 ; }
Reads database record from *db.
Reads database record from * db .
// At the EOF // check if we have room for lengths // Calculate total length of data. // Check if we have room for data items. // OK, we can read the data.