summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-08-07 17:24:54 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-08-07 17:24:54 (EDT)
commitb16bd8260a484a7be8df0528225794a54c42767f (patch)
treec384db9409e8b8cb3343112918a6cb4d89a33ff7 /src
parent60388cb5de1d93636688cabfe84c18759c4d2141 (diff)
downloadmazefight-b16bd8260a484a7be8df0528225794a54c42767f.zip
mazefight-b16bd8260a484a7be8df0528225794a54c42767f.tar.gz
mazefight-b16bd8260a484a7be8df0528225794a54c42767f.tar.bz2
tk: Prevent buffer overrun in text constructor
Diffstat (limited to 'src')
-rw-r--r--src/tk/text.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/tk/text.c b/src/tk/text.c
index 027da71..7406b0b 100644
--- a/src/tk/text.c
+++ b/src/tk/text.c
@@ -303,7 +303,6 @@ mftk_text_new(char min_char, char max_char, int len, const char *val,
t->min_char = min_char;
t->max_char = max_char;
t->len = len;
- t->cur = strlen(val);
t->font = font;
t->line_skip = TTF_FontLineSkip(font);
t->ascent = TTF_FontAscent (font);
@@ -330,6 +329,11 @@ mftk_text_new(char min_char, char max_char, int len, const char *val,
free(w);
return NULL;
}
+
+ t->cur = strlen(val);
+ if (t->cur > t->len) {
+ t->cur = t->len;
+ }
memcpy(t->val, val, t->cur);
w->w = 0;