mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Fixed potential undefined behavior in FullItemDescInBarter
* due to obj_examine_func_hack_objdesc, item description is coped to messageBuffer already (max 354 chars), so in most cases desc is the same as messageBuffer, which should be UB to strncpy_s. MSVC's implementation seems treating self-copy as no-op, but we shouldn't rely on this behavior.
This commit is contained in:
@@ -1756,7 +1756,9 @@ static void __stdcall AppendText(const char* text, const char* desc) {
|
||||
if (desc == nullptr) {
|
||||
desc = fo::util::MessageSearch(&fo::var::proto_main_msg_file, 493);
|
||||
}
|
||||
strncpy_s(messageBuffer, desc, 161);
|
||||
if (desc != messageBuffer) { // safeguard
|
||||
strncpy_s(messageBuffer, desc, 161);
|
||||
}
|
||||
size_t len = strlen(messageBuffer);
|
||||
if (len > 160) {
|
||||
len = 158;
|
||||
|
||||
Reference in New Issue
Block a user