string-util: check for short input in previous_ansi_sequence()
ellipsize_mem() scans backwards for ANSI escape sequences and calls
previous_ansi_sequence(s, t - s, ...) as t walks down toward s. When
t reaches s + 1 the helper is invoked with length == 1 and computes
'length - 2', which wraps to SIZE_MAX - 1.
Follow-up for cb558ab222
This commit is contained in:
@@ -285,6 +285,12 @@ static size_t previous_ansi_sequence(const char *s, size_t length, const char **
|
||||
|
||||
/* Locate the previous ANSI sequence and save its start in *ret_where and return length. */
|
||||
|
||||
if (length < 2) {
|
||||
/* Need at least two bytes for an ANSI sequence */
|
||||
*ret_where = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (size_t i = length - 2; i > 0; i--) { /* -2 because at least two bytes are needed */
|
||||
size_t slen = ansi_sequence_length(s + (i - 1), length - (i - 1));
|
||||
if (slen == 0)
|
||||
|
||||
Reference in New Issue
Block a user