diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2026-05-22 10:06:28 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2026-05-22 10:06:28 +0000 |
| commit | 1067b9bf6964d3da99f663287a84e618d9686127 (patch) | |
| tree | 34b338c101298f9724ee5c61cd8b597d2c960c6a | |
| parent | osc: kitty_clipboard_query(): reply with EPERM if OSC pasting has been disabled (diff) | |
osc: kitty_clipboard_write_finish(): fix walias handlingosc-5522
* 'i' was never incremented, meaning we stored the *last* walias in
the *first alias position in the mime-type list passed to the
clipboard handling. The remaining elements were uninitialized and
invalid.
* We only asserted that we'd found the target mime-type of a
walias. But we need to handle it NOT being found, as it's perfectly
possible for a user to send an "invalid" walias, where the target
mime-type has NOT been sent in a wdata packet.
Diffstat (limited to '')
| -rw-r--r-- | osc.c | 26 |
1 files changed, 20 insertions, 6 deletions
@@ -567,7 +567,9 @@ kitty_clipboard_write_finish(struct terminal *term) /* Remove without freeing, data is now owned by clip */ tll_remove(term->kitty_clipboard.committed_mime_data, it); } + xassert(i == data_count); + /* i keeps counting... */ tll_foreach(term->kitty_clipboard.mime_aliases, it) { const struct kitty_mime_alias *alias = &it->item; @@ -579,16 +581,28 @@ kitty_clipboard_write_finish(struct terminal *term) break; } } - xassert(idx >= 0); - xassert(idx < data_count); - clip.mime_data_map[i].mime_type = alias->alias; - clip.mime_data_map[i].data_idx = idx; + if (likely(idx >= 0)) { + xassert(idx < data_count); + + clip.mime_data_map[i].mime_type = alias->alias; + clip.mime_data_map[i].data_idx = idx; + i++; + + /* TODO: can we make target point to the original mime-type, so that we don't have to free it here? */ + free(alias->target); + } else { + LOG_WARN( + "OSC-5522: invalid WALIAS: %s is not a valid target mime-type", + alias->target); + free(alias->target); + free(alias->alias); + } - /* TODO: can we make target point to the original mime-type, so that we don't have to free it here? */ - free(alias->target); tll_remove(term->kitty_clipboard.mime_aliases, it); } + xassert(i <= mime_count); /* We _may_ have fewer, if there were invalid walias */ + clip.mime_data_map_count = i; if (!term->kitty_clipboard.for_primary) text_to_clipboard(seat, term, NULL, &clip, seat->kbd.serial); |
