Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loop exit conditions in OATH #114

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions applets/oath/oath.c
Original file line number Diff line number Diff line change
@@ -304,11 +304,7 @@ static int oath_list(const CAPDU *capdu, RAPDU *rapdu) {
const size_t n_records = size / sizeof(OATH_RECORD);
size_t off = 0;

while (off < LE) {
if (record_idx >= n_records) {
oath_remaining_type = REMAINING_NONE;
break;
}
while (record_idx < n_records) {
if (read_file(OATH_FILE, &record, record_idx * sizeof(OATH_RECORD), sizeof(OATH_RECORD)) < 0) return -1;
if (off + 3 + record.name_len > LE) { // tag (1) + name_len (1) + algo (1) + name
// shouldn't increase the record_idx in this case
@@ -324,6 +320,9 @@ static int oath_list(const CAPDU *capdu, RAPDU *rapdu) {
memcpy(RDATA + off, record.name, record.name_len);
off += record.name_len;
}
if (record_idx >= n_records) {
oath_remaining_type = REMAINING_NONE;
}
LL = off;

return 0;
@@ -548,11 +547,7 @@ static int oath_calculate_all(const CAPDU *capdu, RAPDU *rapdu) {
OATH_RECORD record;
const size_t n_records = size / sizeof(OATH_RECORD);
size_t off_out = 0;
while (off_out < LE) {
if (record_idx >= n_records) {
oath_remaining_type = REMAINING_NONE;
break;
}
while (record_idx < n_records) {
const size_t file_offset = record_idx * sizeof(OATH_RECORD);
if (read_file(OATH_FILE, &record, file_offset, sizeof(OATH_RECORD)) < 0) return -1;
const size_t estimated_len = 2 + record.name_len + 2 + 1 + (oath_remaining_type == REMAINING_CALC_TRUNC ? 4 : SHA512_DIGEST_LENGTH);
@@ -600,6 +595,9 @@ static int oath_calculate_all(const CAPDU *capdu, RAPDU *rapdu) {
off_out += RDATA[off_out - 1];
}
}
if (record_idx >= n_records) {
oath_remaining_type = REMAINING_NONE;
}
LL = off_out;

return 0;