Commit f82fd912 authored by Chen Bill's avatar Chen Bill Committed by GitHub

fix bounds checking in DeckManager::LoadLFListSingle (#2685)

parent d2c5bc2f
#include "deck_manager.h" #include "deck_manager.h"
#include "game.h"
#include "myfilesystem.h" #include "myfilesystem.h"
#include "network.h" #include "network.h"
#include "game.h"
namespace ygo { namespace ygo {
...@@ -18,19 +18,16 @@ void DeckManager::LoadLFListSingle(const char* path) { ...@@ -18,19 +18,16 @@ void DeckManager::LoadLFListSingle(const char* path) {
if(linebuf[0] == '#') if(linebuf[0] == '#')
continue; continue;
if(linebuf[0] == '!') { if(linebuf[0] == '!') {
int sa = BufferIO::DecodeUTF8(&linebuf[1], strBuffer); auto len = std::strcspn(linebuf, "\r\n");
while(strBuffer[sa - 1] == L'\r' || strBuffer[sa - 1] == L'\n' ) linebuf[len] = 0;
sa--; BufferIO::DecodeUTF8(&linebuf[1], strBuffer);
strBuffer[sa] = 0;
LFList newlist; LFList newlist;
newlist.listName = strBuffer;
newlist.hash = 0x7dfcee6a;
_lfList.push_back(newlist); _lfList.push_back(newlist);
cur = _lfList.rbegin(); cur = _lfList.rbegin();
cur->listName = strBuffer;
cur->hash = 0x7dfcee6a;
continue; continue;
} }
if(linebuf[0] == 0)
continue;
int code = 0; int code = 0;
int count = -1; int count = -1;
if (sscanf(linebuf, "%d %d", &code, &count) != 2) if (sscanf(linebuf, "%d %d", &code, &count) != 2)
...@@ -269,13 +266,13 @@ FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) { ...@@ -269,13 +266,13 @@ FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) {
FILE* fp = myfopen(file, mode); FILE* fp = myfopen(file, mode);
return fp; return fp;
} }
IReadFile* DeckManager::OpenDeckReader(const wchar_t* file) { irr::io::IReadFile* DeckManager::OpenDeckReader(const wchar_t* file) {
#ifdef _WIN32 #ifdef _WIN32
IReadFile* reader = DataManager::FileSystem->createAndOpenFile(file); auto reader = DataManager::FileSystem->createAndOpenFile(file);
#else #else
char file2[256]; char file2[256];
BufferIO::EncodeUTF8(file, file2); BufferIO::EncodeUTF8(file, file2);
IReadFile* reader = DataManager::FileSystem->createAndOpenFile(file2); auto reader = DataManager::FileSystem->createAndOpenFile(file2);
#endif #endif
return reader; return reader;
} }
......
...@@ -54,7 +54,7 @@ public: ...@@ -54,7 +54,7 @@ public:
void GetCategoryPath(wchar_t* ret, int index, const wchar_t* text); void GetCategoryPath(wchar_t* ret, int index, const wchar_t* text);
void GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck); void GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
FILE* OpenDeckFile(const wchar_t* file, const char* mode); FILE* OpenDeckFile(const wchar_t* file, const char* mode);
IReadFile* OpenDeckReader(const wchar_t* file); irr::io::IReadFile* OpenDeckReader(const wchar_t* file);
bool LoadCurrentDeck(const wchar_t* file, bool is_packlist = false); bool LoadCurrentDeck(const wchar_t* file, bool is_packlist = false);
bool LoadCurrentDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck); bool LoadCurrentDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
bool SaveDeck(Deck& deck, const wchar_t* file); bool SaveDeck(Deck& deck, const wchar_t* file);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment