diff options
-rw-r--r-- | st.c | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -146,7 +146,8 @@ typedef struct { | |||
146 | /* ESC type [[ [<priv>] <arg> [;]] <mode>] ESC '\' */ | 146 | /* ESC type [[ [<priv>] <arg> [;]] <mode>] ESC '\' */ |
147 | typedef struct { | 147 | typedef struct { |
148 | char type; /* ESC type ... */ | 148 | char type; /* ESC type ... */ |
149 | char buf[STR_BUF_SIZ]; /* raw string */ | 149 | char *buf; /* allocated raw string */ |
150 | size_t siz; /* allocation size */ | ||
150 | size_t len; /* raw string length */ | 151 | size_t len; /* raw string length */ |
151 | char *args[STR_ARG_SIZ]; | 152 | char *args[STR_ARG_SIZ]; |
152 | int narg; /* nb of args */ | 153 | int narg; /* nb of args */ |
@@ -1948,7 +1949,10 @@ strdump(void) | |||
1948 | void | 1949 | void |
1949 | strreset(void) | 1950 | strreset(void) |
1950 | { | 1951 | { |
1951 | memset(&strescseq, 0, sizeof(strescseq)); | 1952 | strescseq = (STREscape){ |
1953 | .buf = xrealloc(strescseq.buf, STR_BUF_SIZ), | ||
1954 | .siz = STR_BUF_SIZ, | ||
1955 | }; | ||
1952 | } | 1956 | } |
1953 | 1957 | ||
1954 | void | 1958 | void |
@@ -2330,7 +2334,7 @@ tputc(Rune u) | |||
2330 | if (term.esc&ESC_DCS && strescseq.len == 0 && u == 'q') | 2334 | if (term.esc&ESC_DCS && strescseq.len == 0 && u == 'q') |
2331 | term.mode |= MODE_SIXEL; | 2335 | term.mode |= MODE_SIXEL; |
2332 | 2336 | ||
2333 | if (strescseq.len+len >= sizeof(strescseq.buf)) { | 2337 | if (strescseq.len+len >= strescseq.siz) { |
2334 | /* | 2338 | /* |
2335 | * Here is a bug in terminals. If the user never sends | 2339 | * Here is a bug in terminals. If the user never sends |
2336 | * some code to stop the str or esc command, then st | 2340 | * some code to stop the str or esc command, then st |
@@ -2344,7 +2348,10 @@ tputc(Rune u) | |||
2344 | * term.esc = 0; | 2348 | * term.esc = 0; |
2345 | * strhandle(); | 2349 | * strhandle(); |
2346 | */ | 2350 | */ |
2347 | return; | 2351 | if (strescseq.siz > (SIZE_MAX - UTF_SIZ) / 2) |
2352 | return; | ||
2353 | strescseq.siz *= 2; | ||
2354 | strescseq.buf = xrealloc(strescseq.buf, strescseq.siz); | ||
2348 | } | 2355 | } |
2349 | 2356 | ||
2350 | memmove(&strescseq.buf[strescseq.len], c, len); | 2357 | memmove(&strescseq.buf[strescseq.len], c, len); |