Skip to content

Commit

Permalink
Merge pull request #627 from sebholt/fix_pilot_cpp
Browse files Browse the repository at this point in the history
Fix uninitialized string buffer access in pilot cpp
  • Loading branch information
pzychotic authored Oct 9, 2024
2 parents 48c8775 + 8345055 commit 89b5a80
Showing 1 changed file with 10 additions and 12 deletions.
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

0 comments on commit 89b5a80

Please sign in to comment.