Files
Descent3/tools/HogMaker/HogFormat.cpp
Azamat H. Hackimov 6352ab21b9 Fix possible heap buffer overflow
Strict size of name of entry with 36 bytes.
Thanks to MaddTheSane for pointing out.
2024-04-22 02:37:42 +03:00

53 lines
1.5 KiB
C++

/*
* Descent 3
* Copyright (C) 2024 Descent Developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "HogFormat.h"
#include "IOOps.h"
#include <fstream>
namespace D3 {
std::ostream &operator<<(std::ostream &output, HogHeader &header) {
output.write((char *)&header.tag[0], 4);
bin_write(output, header.nfiles);
bin_write(output, header.file_data_offset);
output.write((char *)&header.reserved[0], 56);
return output;
}
std::ostream &operator<<(std::ostream &output, HogFileEntry &entry) {
output.write((char *)&entry.name[0], 36);
bin_write(output, entry.flags);
bin_write(output, entry.len);
bin_write(output, entry.timestamp);
return output;
}
std::ostream &operator<<(std::ostream &output, HogFormat &format) {
output << format.m_header;
for (auto i : format.m_file_entries) {
output << i;
}
return output;
}
} // namespace D3