don't use strncpy
This commit is contained in:
+16
-6
@@ -11,6 +11,16 @@ using namespace std;
|
||||
|
||||
|
||||
|
||||
License::License() {
|
||||
memset(this->username, 0, 20);
|
||||
memset(this->bb_password, 0, 20);
|
||||
this->serial_number = 0;
|
||||
memset(this->access_key, 0, 16);
|
||||
memset(this->gc_password, 0, 12);
|
||||
this->privileges = 0;
|
||||
this->ban_end_time = 0;
|
||||
}
|
||||
|
||||
string License::str() const {
|
||||
string ret = string_printf("License(serial_number=%" PRIu32, this->serial_number);
|
||||
if (this->username[0]) {
|
||||
@@ -148,9 +158,9 @@ shared_ptr<const License> LicenseManager::create_license_pc(
|
||||
shared_ptr<License> l(new License());
|
||||
memset(l.get(), 0, sizeof(License));
|
||||
l->serial_number = serial_number;
|
||||
strncpy(l->access_key, access_key, 8);
|
||||
strlcpy(l->access_key, access_key, 8);
|
||||
if (password) {
|
||||
strncpy(l->gc_password, password, 8);
|
||||
strlcpy(l->gc_password, password, 8);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
@@ -160,9 +170,9 @@ shared_ptr<const License> LicenseManager::create_license_gc(
|
||||
shared_ptr<License> l(new License());
|
||||
memset(l.get(), 0, sizeof(License));
|
||||
l->serial_number = serial_number;
|
||||
strncpy(l->access_key, access_key, 12);
|
||||
strlcpy(l->access_key, access_key, 12);
|
||||
if (password) {
|
||||
strncpy(l->gc_password, password, 8);
|
||||
strlcpy(l->gc_password, password, 8);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
@@ -172,7 +182,7 @@ shared_ptr<const License> LicenseManager::create_license_bb(
|
||||
shared_ptr<License> l(new License());
|
||||
memset(l.get(), 0, sizeof(License));
|
||||
l->serial_number = serial_number;
|
||||
strncpy(l->username, username, 19);
|
||||
strncpy(l->bb_password, password, 19);
|
||||
strlcpy(l->username, username, 19);
|
||||
strlcpy(l->bb_password, password, 19);
|
||||
return l;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ struct License {
|
||||
uint32_t privileges; // privilege level
|
||||
uint64_t ban_end_time; // end time of ban (zero = not banned)
|
||||
|
||||
License();
|
||||
std::string str() const;
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
+13
-7
@@ -16,6 +16,9 @@ using namespace std;
|
||||
|
||||
|
||||
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
|
||||
static FileContentsCache file_cache;
|
||||
|
||||
|
||||
@@ -263,7 +266,7 @@ void send_pc_gc_split_reconnect(shared_ptr<Client> c, uint32_t address,
|
||||
uint32_t gc_address;
|
||||
uint16_t gc_port;
|
||||
uint8_t unused2[0xB0 - 0x23];
|
||||
} __attribute__((packed)) cmd;
|
||||
} cmd;
|
||||
memset(&cmd, 0, sizeof(cmd));
|
||||
cmd.pc_address = bswap32(address);
|
||||
cmd.pc_port = pc_port;
|
||||
@@ -2086,10 +2089,10 @@ static void send_quest_open_file_pc_gc(shared_ptr<Client> c,
|
||||
char filename[0x10];
|
||||
uint32_t file_size;
|
||||
} cmd;
|
||||
strncpy(cmd.name, filename.c_str(), 0x20);
|
||||
cmd.unused = 0;
|
||||
memset(&cmd, 0, sizeof(cmd));
|
||||
strlcpy(cmd.name, filename.c_str(), 0x20);
|
||||
cmd.flags = 2 + is_ep3_quest;
|
||||
strncpy(cmd.filename, filename.c_str(), 0x10);
|
||||
strlcpy(cmd.filename, filename.c_str(), 0x10);
|
||||
cmd.file_size = file_size;
|
||||
send_command(c, is_download_quest ? 0xA6 : 0x44, 0x00, cmd);
|
||||
}
|
||||
@@ -2104,9 +2107,9 @@ static void send_quest_open_file_bb(shared_ptr<Client> c,
|
||||
uint32_t file_size;
|
||||
char name[0x18];
|
||||
} cmd;
|
||||
memset(cmd.unused, 0, 0x22);
|
||||
memset(&cmd, 0, sizeof(cmd));
|
||||
cmd.flags = 2 + is_ep3_quest;
|
||||
strncpy(cmd.filename, filename.c_str(), 0x10);
|
||||
strlcpy(cmd.filename, filename.c_str(), 0x10);
|
||||
cmd.file_size = file_size;
|
||||
send_command(c, is_download_quest ? 0xA6 : 0x44, 0x00, cmd);
|
||||
}
|
||||
@@ -2122,7 +2125,8 @@ static void send_quest_file_chunk(shared_ptr<Client> c, const char* filename,
|
||||
uint8_t data[0x400];
|
||||
uint32_t data_size;
|
||||
} cmd;
|
||||
strncpy(cmd.filename, filename, 0x10);
|
||||
memset(cmd.filename, 0, 0x10);
|
||||
strlcpy(cmd.filename, filename, 0x10);
|
||||
memcpy(cmd.data, data, size);
|
||||
if (size < 0x400) {
|
||||
memset(&cmd.data[size], 0, 0x400 - size);
|
||||
@@ -2184,3 +2188,5 @@ void send_change_event(shared_ptr<Lobby> l, uint8_t new_event) {
|
||||
void send_change_event(shared_ptr<ServerState> s, uint8_t new_event) {
|
||||
send_command(s, 0xDA, new_event);
|
||||
}
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
Reference in New Issue
Block a user