From bdf635e39dac0cac3c805fa9c1fe0d6c7c59df07 Mon Sep 17 00:00:00 2001 From: d0k3 Date: Mon, 4 Jun 2018 00:50:54 +0200 Subject: [PATCH] Fix a potential buffer overflow thanks @windows-server-2003 ! --- arm9/source/common/ui.c | 4 +--- arm9/source/godmode.c | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/arm9/source/common/ui.c b/arm9/source/common/ui.c index f6cb3c5..195f21b 100644 --- a/arm9/source/common/ui.c +++ b/arm9/source/common/ui.c @@ -345,9 +345,7 @@ void TruncateString(char* dest, const char* orig, int nsize, int tpos) { int osize = strnlen(orig, 256); if (nsize < 0) { return; - } else if (nsize <= 3) { - snprintf(dest, nsize, "%s", orig); - } else if (nsize >= osize) { + } else if ((nsize <= 3) || (nsize >= osize)) { snprintf(dest, nsize + 1, "%s", orig); } else { if (tpos + 3 > nsize) tpos = nsize - 3; diff --git a/arm9/source/godmode.c b/arm9/source/godmode.c index 1d33b58..0997f12 100644 --- a/arm9/source/godmode.c +++ b/arm9/source/godmode.c @@ -914,7 +914,7 @@ u32 FileAttrMenu(const char* file_path) { return 1; } - char namestr[32]; + char namestr[32 + 1]; char sizestr[32]; TruncateString(namestr, fno.fname, 32, 8); FormatNumber(sizestr, fno.fsize);