aboutsummaryrefslogtreecommitdiff
path: root/NitrokeyManager.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2017-04-14 12:30:16 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2017-04-14 13:06:31 +0200
commit6e5847809c5c4c68f916fda4351c0b5e279915ed (patch)
tree4f4f77c5d70d9f515ba01296f26a615a97bd74c7 /NitrokeyManager.cc
parentd2089636399b4b0d26f22e072a9801b915acfc74 (diff)
downloadlibnitrokey-6e5847809c5c4c68f916fda4351c0b5e279915ed.tar.gz
libnitrokey-6e5847809c5c4c68f916fda4351c0b5e279915ed.tar.bz2
Security: exchange strdup with strndup
Keep build directory (removed in earlier commit) Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'NitrokeyManager.cc')
-rw-r--r--NitrokeyManager.cc16
1 files changed, 9 insertions, 7 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index faeaf03..60c1a24 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -472,11 +472,13 @@ namespace nitrokey{
return get_slot_name(slot_number);
}
- const char * NitrokeyManager::get_slot_name(uint8_t slot_number) {
+ static const int max_string_field_length = 100;
+
+ const char * NitrokeyManager::get_slot_name(uint8_t slot_number) {
auto payload = get_payload<GetSlotName>();
payload.slot_number = slot_number;
auto resp = GetSlotName::CommandTransaction::run(device, payload);
- return strdup((const char *) resp.data().slot_name);
+ return strndup((const char *) resp.data().slot_name, max_string_field_length);
}
bool NitrokeyManager::first_authenticate(const char *pin, const char *temporary_password) {
@@ -583,7 +585,7 @@ namespace nitrokey{
auto p = get_payload<GetPasswordSafeSlotName>();
p.slot_number = slot_number;
auto response = GetPasswordSafeSlotName::CommandTransaction::run(device, p);
- return strdup((const char *) response.data().slot_name);
+ return strndup((const char *) response.data().slot_name, max_string_field_length);
}
bool NitrokeyManager::is_valid_password_safe_slot_number(uint8_t slot_number) const { return slot_number < 16; }
@@ -593,7 +595,7 @@ namespace nitrokey{
auto p = get_payload<GetPasswordSafeSlotLogin>();
p.slot_number = slot_number;
auto response = GetPasswordSafeSlotLogin::CommandTransaction::run(device, p);
- return strdup((const char *) response.data().slot_login);
+ return strndup((const char *) response.data().slot_login, max_string_field_length);
}
const char *NitrokeyManager::get_password_safe_slot_password(uint8_t slot_number) {
@@ -601,7 +603,7 @@ namespace nitrokey{
auto p = get_payload<GetPasswordSafeSlotPassword>();
p.slot_number = slot_number;
auto response = GetPasswordSafeSlotPassword::CommandTransaction::run(device, p);
- return strdup((const char *) response.data().slot_password); //FIXME use secure way
+ return strndup((const char *) response.data().slot_password, max_string_field_length); //FIXME use secure way
}
void NitrokeyManager::write_password_safe_slot(uint8_t slot_number, const char *slot_name, const char *slot_login,
@@ -816,7 +818,7 @@ namespace nitrokey{
const char * NitrokeyManager::get_status_storage_as_string(){
auto p = stick20::GetDeviceStatus::CommandTransaction::run(device);
- return strdup(p.data().dissect().c_str());
+ return strndup(p.data().dissect().c_str(), max_string_field_length);
}
stick20::DeviceConfigurationResponsePacket::ResponsePayload NitrokeyManager::get_status_storage(){
@@ -826,7 +828,7 @@ namespace nitrokey{
const char * NitrokeyManager::get_SD_usage_data_as_string(){
auto p = stick20::GetSDCardOccupancy::CommandTransaction::run(device);
- return strdup(p.data().dissect().c_str());
+ return strndup(p.data().dissect().c_str(), max_string_field_length);
}
std::pair<uint8_t,uint8_t> NitrokeyManager::get_SD_usage_data(){