aboutsummaryrefslogtreecommitdiff
path: root/src/vterm/parser.c
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2024-08-19 06:43:06 -0500
committerGitHub <noreply@github.com>2024-08-19 06:43:06 -0500
commit6d997f8068a89703823f1572c56a6331c9e024aa (patch)
tree30cef4140fa7b3017d7a754b508eb159335382d0 /src/vterm/parser.c
parent33464189bc02b2555e26dc4e9f7b3fbbcdd02490 (diff)
downloadrneovim-6d997f8068a89703823f1572c56a6331c9e024aa.tar.gz
rneovim-6d997f8068a89703823f1572c56a6331c9e024aa.tar.bz2
rneovim-6d997f8068a89703823f1572c56a6331c9e024aa.zip
fix(terminal): handle C0 characters in OSC terminator (#30090)
When a C0 character is present in an OSC terminator (i.e. after the ESC but before a \ (0x5c) or printable character), vterm executes the control character and resets the current string fragment. If the C0 character is the final byte in the sequence, the string fragment has a zero length. However, because the VT parser is still in the "escape" state, vterm attempts to subtract 1 from the string length (to account for the escape character). When the string fragment is empty, this causes an underflow in the unsigned size variable, resulting in a buffer overflow. The fix is simple: explicitly check if the string length is non-zero before subtracting.
Diffstat (limited to 'src/vterm/parser.c')
-rw-r--r--src/vterm/parser.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/vterm/parser.c b/src/vterm/parser.c
index b43a549cef..84d017a791 100644
--- a/src/vterm/parser.c
+++ b/src/vterm/parser.c
@@ -1,5 +1,6 @@
#include "vterm_internal.h"
+#include <assert.h>
#include <stdio.h>
#include <string.h>
@@ -190,8 +191,10 @@ size_t vterm_input_write(VTerm *vt, const char *bytes, size_t len)
((!IS_STRING_STATE() || c == 0x5c))) {
c += 0x40;
c1_allowed = true;
- if(string_len)
+ if(string_len) {
+ assert(string_len > 0);
string_len -= 1;
+ }
vt->parser.in_esc = false;
}
else {
@@ -377,9 +380,12 @@ string_state:
if(string_start) {
size_t string_len = bytes + pos - string_start;
- if(vt->parser.in_esc)
- string_len -= 1;
- string_fragment(vt, string_start, string_len, false);
+ if (string_len > 0) {
+ if(vt->parser.in_esc) {
+ string_len -= 1;
+ }
+ string_fragment(vt, string_start, string_len, false);
+ }
}
return len;