Fix a potential buffer overflow

thanks @windows-server-2003 !
This commit is contained in:
d0k3 2018-06-04 00:50:54 +02:00
parent 0cbcce5579
commit bdf635e39d
2 changed files with 2 additions and 4 deletions

View File

@ -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;

View File

@ -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);