Skip to content

Commit c8318ca

Browse files
Enforce calldata offset alignment
1 parent 601c828 commit c8318ca

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/features/generic_tx_parser/gtp_data_path.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,19 @@ static bool path_tuple(const s_tuple_args *tuple, uint32_t *offset, uint32_t *re
110110

111111
static bool path_ref(uint32_t *offset, uint32_t *ref_offset) {
112112
uint8_t buf[sizeof(uint16_t)];
113+
uint16_t raw_offset;
113114
const uint8_t *chunk;
114115

115116
if ((chunk = calldata_get_chunk(get_current_calldata(), *offset)) == NULL) {
116117
return false;
117118
}
118119
buf_shrink_expand(chunk, CALLDATA_CHUNK_SIZE, buf, sizeof(buf));
119-
*offset = read_u16_be(buf, 0) / CALLDATA_CHUNK_SIZE;
120+
raw_offset = read_u16_be(buf, 0);
121+
if ((raw_offset % CALLDATA_CHUNK_SIZE) != 0) {
122+
// reject unaligned offsets
123+
return false;
124+
}
125+
*offset = raw_offset / CALLDATA_CHUNK_SIZE;
120126
*offset += *ref_offset;
121127
return true;
122128
}

0 commit comments

Comments
 (0)