diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/pango.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/common/pango.c b/common/pango.c index ba74692e..f0b8db66 100644 --- a/common/pango.c +++ b/common/pango.c | |||
@@ -10,6 +10,9 @@ | |||
10 | #include "log.h" | 10 | #include "log.h" |
11 | #include "stringop.h" | 11 | #include "stringop.h" |
12 | 12 | ||
13 | static const char *overflow = "[buffer overflow]"; | ||
14 | static const int max_chars = 16384; | ||
15 | |||
13 | size_t escape_markup_text(const char *src, char *dest) { | 16 | size_t escape_markup_text(const char *src, char *dest) { |
14 | size_t length = 0; | 17 | size_t length = 0; |
15 | if (dest) { | 18 | if (dest) { |
@@ -84,12 +87,12 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, | |||
84 | 87 | ||
85 | void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, | 88 | void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, |
86 | int *baseline, double scale, bool markup, const char *fmt, ...) { | 89 | int *baseline, double scale, bool markup, const char *fmt, ...) { |
87 | static char buf[2048]; | 90 | char buf[max_chars]; |
88 | 91 | ||
89 | va_list args; | 92 | va_list args; |
90 | va_start(args, fmt); | 93 | va_start(args, fmt); |
91 | if (vsnprintf(buf, 2048, fmt, args) >= 2048) { | 94 | if (vsnprintf(buf, sizeof(buf), fmt, args) >= max_chars) { |
92 | strcpy(buf, "[buffer overflow]"); | 95 | strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow); |
93 | } | 96 | } |
94 | va_end(args); | 97 | va_end(args); |
95 | 98 | ||
@@ -104,12 +107,12 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, | |||
104 | 107 | ||
105 | void pango_printf(cairo_t *cairo, const char *font, | 108 | void pango_printf(cairo_t *cairo, const char *font, |
106 | double scale, bool markup, const char *fmt, ...) { | 109 | double scale, bool markup, const char *fmt, ...) { |
107 | static char buf[2048]; | 110 | char buf[max_chars]; |
108 | 111 | ||
109 | va_list args; | 112 | va_list args; |
110 | va_start(args, fmt); | 113 | va_start(args, fmt); |
111 | if (vsnprintf(buf, 2048, fmt, args) >= 2048) { | 114 | if (vsnprintf(buf, sizeof(buf), fmt, args) >= max_chars) { |
112 | strcpy(buf, "[buffer overflow]"); | 115 | strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow); |
113 | } | 116 | } |
114 | va_end(args); | 117 | va_end(args); |
115 | 118 | ||