Skip to content

Commit 5a5f50a

Browse files
adopt improved CSI Ps @ parsing from newer flanterm, including its DoS fix
1 parent 6b943d3 commit 5a5f50a

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

src/flanterm/flanterm.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -699,17 +699,30 @@ static void control_sequence_parse(struct flanterm_context *ctx, uint8_t c) {
699699
break;
700700
}
701701
break;
702-
case '@':
703-
for (size_t i = ctx->cols - 1;; i--) {
704-
ctx->move_character(ctx, i + ctx->esc_values[0], y, i, y);
705-
ctx->set_cursor_pos(ctx, i, y);
702+
case '@': {
703+
size_t n = ctx->esc_values[0];
704+
705+
if (n == 0) {
706+
break;
707+
}
708+
709+
if (n > ctx->cols - x) {
710+
n = ctx->cols - x;
711+
}
712+
713+
for (size_t i = ctx->cols - n; i-- > x;) {
714+
ctx->move_character(ctx, i + n, y, i, y);
715+
}
716+
717+
ctx->set_cursor_pos(ctx, x, y);
718+
719+
for (size_t i = 0; i < n; i++) {
706720
ctx->raw_putchar(ctx, ' ');
707-
if (i == x) {
708-
break;
709-
}
710721
}
722+
711723
ctx->set_cursor_pos(ctx, x, y);
712724
break;
725+
}
713726
case 'P':
714727
for (size_t i = x + ctx->esc_values[0]; i < ctx->cols; i++)
715728
ctx->move_character(ctx, i - ctx->esc_values[0], y, i, y);

0 commit comments

Comments
 (0)