summaryrefslogtreecommitdiff
path: root/NitrokeyManager.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-08-09 15:15:17 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-08-09 18:34:00 +0200
commit9d6e045a3143f8eb31c5033c9c4be59cc2f73336 (patch)
treecdda7d8d8866ae2c63aba812cbb2efe2f2b657b0 /NitrokeyManager.cc
parent0f2965f5808386f9dd89209d754fd827ef2b27bd (diff)
downloadlibnitrokey-9d6e045a3143f8eb31c5033c9c4be59cc2f73336.tar.gz
libnitrokey-9d6e045a3143f8eb31c5033c9c4be59cc2f73336.tar.bz2
Return error for too long string
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'NitrokeyManager.cc')
-rw-r--r--NitrokeyManager.cc9
1 files changed, 6 insertions, 3 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index 5baf7bd..c27de2b 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -2,15 +2,18 @@
#include <cstring>
#include <iostream>
#include "include/NitrokeyManager.h"
+#include "include/TooLongStringException.h"
namespace nitrokey{
template <typename T>
void strcpyT(T& dest, const char* src){
assert(src != nullptr);
- const size_t s = sizeof dest;
- assert(strlen(src) <= s); // FIXME should throw an exception to abort when too long string appears
- strncpy((char*) &dest, src, s);
+ const size_t s_dest = sizeof dest;
+ if (strlen(src) > s_dest){
+ throw TooLongStringException(strlen(src), s_dest, src);
+ }
+ strncpy((char*) &dest, src, s_dest);
}
template <typename T>