mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 13:42:47 +00:00
Fix potential buffer overflows
This commit is contained in:
parent
ffa5eaaae4
commit
c10f6d1f9e
@ -956,7 +956,7 @@ bool ShowProgress(u64 current, u64 total, const char* opstr)
|
|||||||
DrawRectangle(MAIN_SCREEN, bar_pos_x + 2, bar_pos_y + 2, prog_width, bar_height - 4, COLOR_STD_FONT);
|
DrawRectangle(MAIN_SCREEN, bar_pos_x + 2, bar_pos_y + 2, prog_width, bar_height - 4, COLOR_STD_FONT);
|
||||||
DrawRectangle(MAIN_SCREEN, bar_pos_x + 2 + prog_width, bar_pos_y + 2, (bar_width-4) - prog_width, bar_height - 4, COLOR_STD_BG);
|
DrawRectangle(MAIN_SCREEN, bar_pos_x + 2 + prog_width, bar_pos_y + 2, (bar_width-4) - prog_width, bar_height - 4, COLOR_STD_BG);
|
||||||
|
|
||||||
TruncateString(progstr, opstr, (bar_width / FONT_WIDTH_EXT) - 7, 8);
|
TruncateString(progstr, opstr, min(63, (bar_width / FONT_WIDTH_EXT) - 7), 8);
|
||||||
snprintf(tempstr, 64, "%s (%lu%%)", progstr, prog_percent);
|
snprintf(tempstr, 64, "%s (%lu%%)", progstr, prog_percent);
|
||||||
ResizeString(progstr, tempstr, bar_width / FONT_WIDTH_EXT, 8, false);
|
ResizeString(progstr, tempstr, bar_width / FONT_WIDTH_EXT, 8, false);
|
||||||
DrawString(MAIN_SCREEN, progstr, bar_pos_x, text_pos_y, COLOR_STD_FONT, COLOR_STD_BG, true);
|
DrawString(MAIN_SCREEN, progstr, bar_pos_x, text_pos_y, COLOR_STD_FONT, COLOR_STD_BG, true);
|
||||||
|
@ -159,7 +159,7 @@ void DrawTopBar(const char* curr_path) {
|
|||||||
|
|
||||||
// top bar - current path
|
// top bar - current path
|
||||||
DrawRectangle(TOP_SCREEN, 0, 0, SCREEN_WIDTH_TOP, 12, COLOR_TOP_BAR);
|
DrawRectangle(TOP_SCREEN, 0, 0, SCREEN_WIDTH_TOP, 12, COLOR_TOP_BAR);
|
||||||
if (*curr_path) TruncateString(tempstr, curr_path, len_path / FONT_WIDTH_EXT, 8);
|
if (*curr_path) TruncateString(tempstr, curr_path, min(63, len_path / FONT_WIDTH_EXT), 8);
|
||||||
else snprintf(tempstr, 16, "[root]");
|
else snprintf(tempstr, 16, "[root]");
|
||||||
DrawStringF(TOP_SCREEN, bartxt_x, bartxt_start, COLOR_STD_BG, COLOR_TOP_BAR, "%s", tempstr);
|
DrawStringF(TOP_SCREEN, bartxt_x, bartxt_start, COLOR_STD_BG, COLOR_TOP_BAR, "%s", tempstr);
|
||||||
bool show_time = true;
|
bool show_time = true;
|
||||||
@ -208,6 +208,7 @@ void DrawUserInterface(const char* curr_path, DirEntry* curr_entry, u32 curr_pan
|
|||||||
const u32 info_start = (MAIN_SCREEN == TOP_SCREEN) ? 18 : 2; // leave space for the topbar when required
|
const u32 info_start = (MAIN_SCREEN == TOP_SCREEN) ? 18 : 2; // leave space for the topbar when required
|
||||||
const u32 instr_x = (SCREEN_WIDTH_MAIN - (34*FONT_WIDTH_EXT)) / 2;
|
const u32 instr_x = (SCREEN_WIDTH_MAIN - (34*FONT_WIDTH_EXT)) / 2;
|
||||||
const u32 len_info = (SCREEN_WIDTH_MAIN - ((SCREEN_WIDTH_MAIN >= 400) ? 80 : 20)) / 2;
|
const u32 len_info = (SCREEN_WIDTH_MAIN - ((SCREEN_WIDTH_MAIN >= 400) ? 80 : 20)) / 2;
|
||||||
|
const u32 str_len_info = min(63, len_info / FONT_WIDTH_EXT);
|
||||||
char tempstr[64];
|
char tempstr[64];
|
||||||
|
|
||||||
static u32 state_prev = 0xFFFFFFFF;
|
static u32 state_prev = 0xFFFFFFFF;
|
||||||
@ -229,12 +230,12 @@ void DrawUserInterface(const char* curr_path, DirEntry* curr_entry, u32 curr_pan
|
|||||||
else snprintf(tempstr, 63, "CURRENT");
|
else snprintf(tempstr, 63, "CURRENT");
|
||||||
DrawStringF(MAIN_SCREEN, 2, info_start, COLOR_STD_FONT, COLOR_STD_BG, "[%s]", tempstr);
|
DrawStringF(MAIN_SCREEN, 2, info_start, COLOR_STD_FONT, COLOR_STD_BG, "[%s]", tempstr);
|
||||||
// file / entry name
|
// file / entry name
|
||||||
ResizeString(tempstr, curr_entry->name, len_info / FONT_WIDTH_EXT, 8, false);
|
ResizeString(tempstr, curr_entry->name, str_len_info, 8, false);
|
||||||
u32 color_current = COLOR_ENTRY(curr_entry);
|
u32 color_current = COLOR_ENTRY(curr_entry);
|
||||||
DrawStringF(MAIN_SCREEN, 4, info_start + 12, color_current, COLOR_STD_BG, "%s", tempstr);
|
DrawStringF(MAIN_SCREEN, 4, info_start + 12, color_current, COLOR_STD_BG, "%s", tempstr);
|
||||||
// size (in Byte) or type desc
|
// size (in Byte) or type desc
|
||||||
if (curr_entry->type == T_DIR) {
|
if (curr_entry->type == T_DIR) {
|
||||||
ResizeString(tempstr, "(dir)", len_info / FONT_WIDTH_EXT, 8, false);
|
ResizeString(tempstr, "(dir)", str_len_info, 8, false);
|
||||||
} else if (curr_entry->type == T_DOTDOT) {
|
} else if (curr_entry->type == T_DOTDOT) {
|
||||||
snprintf(tempstr, 21, "%20s", "");
|
snprintf(tempstr, 21, "%20s", "");
|
||||||
} else if (curr_entry->type == T_ROOT) {
|
} else if (curr_entry->type == T_ROOT) {
|
||||||
@ -246,13 +247,13 @@ void DrawUserInterface(const char* curr_path, DirEntry* curr_entry, u32 curr_pan
|
|||||||
(drvtype & DRV_XORPAD) ? "XORpad" : (drvtype & DRV_MEMORY) ? "Memory" : (drvtype & DRV_ALIAS) ? "Alias" :
|
(drvtype & DRV_XORPAD) ? "XORpad" : (drvtype & DRV_MEMORY) ? "Memory" : (drvtype & DRV_ALIAS) ? "Alias" :
|
||||||
(drvtype & DRV_CART) ? "Gamecart" : (drvtype & DRV_VRAM) ? "VRAM" : (drvtype & DRV_SEARCH) ? "Search" : ""),
|
(drvtype & DRV_CART) ? "Gamecart" : (drvtype & DRV_VRAM) ? "VRAM" : (drvtype & DRV_SEARCH) ? "Search" : ""),
|
||||||
((drvtype & DRV_FAT) ? " FAT" : (drvtype & DRV_VIRTUAL) ? " Virtual" : ""));
|
((drvtype & DRV_FAT) ? " FAT" : (drvtype & DRV_VIRTUAL) ? " Virtual" : ""));
|
||||||
ResizeString(tempstr, drvstr, len_info / FONT_WIDTH_EXT, 8, false);
|
ResizeString(tempstr, drvstr, str_len_info, 8, false);
|
||||||
} else {
|
} else {
|
||||||
char numstr[32];
|
char numstr[32];
|
||||||
char bytestr[32];
|
char bytestr[32];
|
||||||
FormatNumber(numstr, curr_entry->size);
|
FormatNumber(numstr, curr_entry->size);
|
||||||
snprintf(bytestr, 31, "%s Byte", numstr);
|
snprintf(bytestr, 31, "%s Byte", numstr);
|
||||||
ResizeString(tempstr, bytestr, len_info / FONT_WIDTH_EXT, 8, false);
|
ResizeString(tempstr, bytestr, str_len_info, 8, false);
|
||||||
}
|
}
|
||||||
DrawStringF(MAIN_SCREEN, 4, info_start + 12 + 10, color_current, COLOR_STD_BG, tempstr);
|
DrawStringF(MAIN_SCREEN, 4, info_start + 12 + 10, color_current, COLOR_STD_BG, tempstr);
|
||||||
// path of file (if in search results)
|
// path of file (if in search results)
|
||||||
@ -260,10 +261,10 @@ void DrawUserInterface(const char* curr_path, DirEntry* curr_entry, u32 curr_pan
|
|||||||
char dirstr[256];
|
char dirstr[256];
|
||||||
strncpy(dirstr, curr_entry->path, 256);
|
strncpy(dirstr, curr_entry->path, 256);
|
||||||
*(strrchr(dirstr, '/')+1) = '\0';
|
*(strrchr(dirstr, '/')+1) = '\0';
|
||||||
ResizeString(tempstr, dirstr, len_info / FONT_WIDTH_EXT, 8, false);
|
ResizeString(tempstr, dirstr, str_len_info, 8, false);
|
||||||
DrawStringF(MAIN_SCREEN, 4, info_start + 12 + 10 + 10, color_current, COLOR_STD_BG, "%s", tempstr);
|
DrawStringF(MAIN_SCREEN, 4, info_start + 12 + 10 + 10, color_current, COLOR_STD_BG, "%s", tempstr);
|
||||||
} else {
|
} else {
|
||||||
ResizeString(tempstr, "", len_info / FONT_WIDTH_EXT, 8, false);
|
ResizeString(tempstr, "", str_len_info, 8, false);
|
||||||
DrawStringF(MAIN_SCREEN, 4, info_start + 12 + 10 + 10, color_current, COLOR_STD_BG, "%s", tempstr);
|
DrawStringF(MAIN_SCREEN, 4, info_start + 12 + 10 + 10, color_current, COLOR_STD_BG, "%s", tempstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,7 +273,7 @@ void DrawUserInterface(const char* curr_path, DirEntry* curr_entry, u32 curr_pan
|
|||||||
len_info / FONT_WIDTH_EXT, (clipboard->n_entries) ? "[CLIPBOARD]" : "");
|
len_info / FONT_WIDTH_EXT, (clipboard->n_entries) ? "[CLIPBOARD]" : "");
|
||||||
for (u32 c = 0; c < n_cb_show; c++) {
|
for (u32 c = 0; c < n_cb_show; c++) {
|
||||||
u32 color_cb = COLOR_ENTRY(&(clipboard->entry[c]));
|
u32 color_cb = COLOR_ENTRY(&(clipboard->entry[c]));
|
||||||
ResizeString(tempstr, (clipboard->n_entries > c) ? clipboard->entry[c].name : "", len_info / FONT_WIDTH_EXT, 8, true);
|
ResizeString(tempstr, (clipboard->n_entries > c) ? clipboard->entry[c].name : "", str_len_info, 8, true);
|
||||||
DrawStringF(MAIN_SCREEN, SCREEN_WIDTH_MAIN - len_info - 4, info_start + 12 + (c*10), color_cb, COLOR_STD_BG, "%s", tempstr);
|
DrawStringF(MAIN_SCREEN, SCREEN_WIDTH_MAIN - len_info - 4, info_start + 12 + (c*10), color_cb, COLOR_STD_BG, "%s", tempstr);
|
||||||
}
|
}
|
||||||
*tempstr = '\0';
|
*tempstr = '\0';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user