Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix uninitialized string buffer access in pilot cpp #627

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions Descent3/pilot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2798,7 +2798,6 @@ void ShipSelectDeleteLogo(newuiListBox *lb) {
ASSERT(lb);

int selected_index = lb->GetCurrentIndex();
char custom_filename[384];
char custom_logoname[384];

// check for None selected
Expand All @@ -2807,7 +2806,7 @@ void ShipSelectDeleteLogo(newuiListBox *lb) {
return;
}

lb->GetItem(selected_index, custom_logoname, 384);
lb->GetItem(selected_index, custom_logoname, sizeof(custom_logoname));

if ((selected_index - 1) >= (int)Custom_images.size()) {
LOG_FATAL << "Listbox selected item not found";
Expand All @@ -2816,20 +2815,20 @@ void ShipSelectDeleteLogo(newuiListBox *lb) {
}

// Get the filename
std::filesystem::path p = Custom_images[selected_index - 1];
std::filesystem::path custom_filename = Custom_images[selected_index - 1];

// delete custom_filename, we don't want it....
char buffer[512];
snprintf(buffer, sizeof(buffer), TXT_PLTOKDEL, custom_logoname);
if (DoMessageBox(TXT_PLTDELCONF, buffer, MSGBOX_YESNO, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL)) {
LOG_INFO.printf("Deleting pilot logo %s (%s)", custom_logoname, custom_filename);
LOG_INFO.printf("Deleting pilot logo %s (%s)", custom_logoname, custom_filename.u8string().c_str());

std::error_code ec;
if (std::filesystem::remove(LocalCustomGraphicsDir / p, ec)) {
if (std::filesystem::remove(LocalCustomGraphicsDir / custom_filename, ec)) {
// Update the list box, select none
UpdateGraphicsListbox(lb);
} else {
LOG_FATAL.printf("Unable to delete file %s", custom_filename);
LOG_FATAL.printf("Unable to delete file %s", custom_filename.u8string().c_str());
Int3();
}
}
Expand All @@ -2841,7 +2840,6 @@ void ShipSelectDeleteTaunt(pilot *Pilot, newuiComboBox *lb, tAudioTauntComboBoxe
ASSERT(taunt_boxes);

int selected_index = lb->GetCurrentIndex();
char custom_filename[384];
char custom_logoname[384];

// check for None selected
Expand All @@ -2850,7 +2848,7 @@ void ShipSelectDeleteTaunt(pilot *Pilot, newuiComboBox *lb, tAudioTauntComboBoxe
return;
}

lb->GetItem(selected_index, custom_logoname, 384);
lb->GetItem(selected_index, custom_logoname, sizeof(custom_logoname));

if ((selected_index - 1) >= (int)Audio_taunts.size()) {
LOG_FATAL << "Listbox selected item not found";
Expand All @@ -2859,21 +2857,21 @@ void ShipSelectDeleteTaunt(pilot *Pilot, newuiComboBox *lb, tAudioTauntComboBoxe
}

// Get the filename
std::filesystem::path p = Audio_taunts[selected_index - 1];
std::filesystem::path custom_filename = Audio_taunts[selected_index - 1];

// delete custom_filename, we don't want it....
char buffer[512];
snprintf(buffer, sizeof(buffer), TXT_PLTOKDEL, custom_logoname);
if (DoMessageBox(TXT_PLTDELCONF, buffer, MSGBOX_YESNO, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL)) {
LOG_INFO.printf("Deleting audio taunt %s (%s)", custom_logoname, custom_filename);
LOG_INFO.printf("Deleting audio taunt %s (%s)", custom_logoname, custom_filename.u8string().c_str());

std::error_code ec;
if (std::filesystem::remove(LocalCustomSoundsDir / p, ec)) {
if (std::filesystem::remove(LocalCustomSoundsDir / custom_filename, ec)) {
// Update the list boxes, select none
UpdateAudioTauntBoxes(taunt_boxes->taunt_a, taunt_boxes->taunt_b, taunt_boxes->taunt_c, taunt_boxes->taunt_d,
Pilot);
} else {
LOG_FATAL.printf("Unable to delete file %s", custom_filename);
LOG_FATAL.printf("Unable to delete file %s", custom_filename.u8string().c_str());
Int3();
}
}
Expand Down
Loading