diff options
| author | Craig Barnes <craigbarnes@protonmail.com> | 2022-03-02 19:05:51 +0000 |
|---|---|---|
| committer | Craig Barnes <craigbarnes@protonmail.com> | 2022-03-02 19:05:51 +0000 |
| commit | cc8e86fd2d7c2e2527e0c77237ff815888008ac4 (patch) | |
| tree | ee373d8a3dc621bb56b0e8b13681efda750ed89c /dcs.c | |
| parent | Wrap setlocale in asserts since it can fail (diff) | |
dcs: prevent possibility of out-of-bounds reads in decrqss()
This could be triggered by running, for example:
printf '\033P$qrxyz\033\\'
...which would cause a memcmp() of 4 bytes on a 2 byte string literal.
Fixes: #960
Diffstat (limited to 'dcs.c')
| -rw-r--r-- | dcs.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -240,7 +240,7 @@ decrqss(struct terminal *term) * https://github.com/hackerb9/vt340test/issues/13 */ - if (memcmp(query, "r", n) == 0) { + if (n == 1 && query[0] == 'r') { /* DECSTBM - Set Top and Bottom Margins */ char reply[64]; int len = snprintf(reply, sizeof(reply), "\033P1$r%d;%dr\033\\", @@ -249,7 +249,7 @@ decrqss(struct terminal *term) term_to_slave(term, reply, len); } - else if (memcmp(query, "m", n) == 0) { + else if (n == 1 && query[0] == 'm') { /* SGR - Set Graphic Rendition */ char *reply = NULL; size_t len = 0; @@ -356,7 +356,7 @@ decrqss(struct terminal *term) free(reply); } - else if (memcmp(query, " q", n) == 0) { + else if (n == 2 && memcmp(query, " q", 2) == 0) { /* DECSCUSR - Set Cursor Style */ int mode; @@ -376,7 +376,7 @@ decrqss(struct terminal *term) } else { - const char err[] = "\033P0$r\033\\"; + static const char err[] = "\033P0$r\033\\"; term_to_slave(term, err, sizeof(err) - 1); } } |
