diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2016-08-09 15:15:17 +0200 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2016-08-09 18:34:00 +0200 |
commit | 9d6e045a3143f8eb31c5033c9c4be59cc2f73336 (patch) | |
tree | cdda7d8d8866ae2c63aba812cbb2efe2f2b657b0 /NitrokeyManager.cc | |
parent | 0f2965f5808386f9dd89209d754fd827ef2b27bd (diff) | |
download | libnitrokey-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.cc | 9 |
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> |