fix ellipsis buffer overflow in xescape_full and utf8 escapers
This commit is contained in:
committed by
Zbigniew Jędrzejewski-Szmek
parent
5fa2f85c10
commit
17260a97c8
+4
-3
@@ -379,12 +379,13 @@ char* xescape_full(const char *s, const char *bad, size_t console_width, XEscape
|
||||
if (console_width == 0)
|
||||
return strdup("");
|
||||
|
||||
ans = new(char, MIN(strlen(s), console_width) * 4 + 1);
|
||||
size_t body = MIN(strlen(s), console_width) * 4;
|
||||
ans = new(char, body + STRLEN("...") + 1);
|
||||
if (!ans)
|
||||
return NULL;
|
||||
|
||||
memset(ans, '_', MIN(strlen(s), console_width) * 4);
|
||||
ans[MIN(strlen(s), console_width) * 4] = 0;
|
||||
memset(ans, '_', body);
|
||||
ans[body] = 0;
|
||||
|
||||
bool force_ellipsis = FLAGS_SET(flags, XESCAPE_FORCE_ELLIPSIS);
|
||||
|
||||
|
||||
+2
-1
@@ -200,7 +200,8 @@ char* utf8_escape_non_printable_full(const char *str, size_t console_width, bool
|
||||
if (console_width == 0)
|
||||
return strdup("");
|
||||
|
||||
p = s = prev_s = malloc(strlen(str) * 4 + 1);
|
||||
size_t body = strlen(str) * 4;
|
||||
p = s = prev_s = malloc(body + STRLEN("…") + 1);
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user