diff options
author | aristocratos <gnmjpl@gmail.com> | 2022-02-15 07:11:22 +0100 |
---|---|---|
committer | aristocratos <gnmjpl@gmail.com> | 2022-02-15 07:11:22 +0100 |
commit | 2aeae24b880651291a684f14bc7b9a356e8f3980 (patch) | |
tree | bac09b10988e17370b2fd0031a8f284e82ba46fc | |
parent | 58846af5169582692f95ee3244161b1f7a6caf9d (diff) |
Fixed: string to wstring conversion crash when string is too big
-rw-r--r-- | src/btop_tools.cpp | 4 | ||||
-rw-r--r-- | src/linux/btop_collect.cpp | 8 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/btop_tools.cpp b/src/btop_tools.cpp index ba82ab4..58c319b 100644 --- a/src/btop_tools.cpp +++ b/src/btop_tools.cpp @@ -171,7 +171,7 @@ namespace Tools { size_t wide_ulen(const string& str) { unsigned int chars = 0; std::wstring_convert<std::codecvt_utf8<wchar_t>> conv; - auto w_str = conv.from_bytes(str.c_str()); + auto w_str = conv.from_bytes((str.size() > 10000 ? str.substr(0, 10000).c_str() : str.c_str())); for (auto c : w_str) { chars += utf8::wcwidth(c); @@ -194,7 +194,7 @@ namespace Tools { if (len < 1 or str.empty()) return ""; if (wide) { std::wstring_convert<std::codecvt_utf8<wchar_t>> conv; - auto w_str = conv.from_bytes(str.c_str()); + auto w_str = conv.from_bytes((str.size() > 10000 ? str.substr(0, 10000).c_str() : str.c_str())); while (wide_ulen(w_str) > len) w_str.pop_back(); str = conv.to_bytes(w_str); diff --git a/src/linux/btop_collect.cpp b/src/linux/btop_collect.cpp index 62ae505..3e165a8 100644 --- a/src/linux/btop_collect.cpp +++ b/src/linux/btop_collect.cpp @@ -1493,7 +1493,13 @@ namespace Proc { pread.open(d.path() / "cmdline"); if (not pread.good()) continue; long_string.clear(); - while(getline(pread, long_string, '\0')) new_proc.cmd += long_string + ' '; + while(getline(pread, long_string, '\0')) { + new_proc.cmd += long_string + ' '; + if (new_proc.cmd.size() > 1000) { + new_proc.cmd.resize(1000); + break; + } + } pread.close(); if (not new_proc.cmd.empty()) new_proc.cmd.pop_back(); |