Skip to content

Fix ownership issue for string_pointer and buffer overrun issue for string_array. (#472) #474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fixed an error for MSVC.
Added space to error description.
  • Loading branch information
CookStar committed May 27, 2023
commit 9fefc1eae72c57cbddf5be24e4dd670566da5da9
4 changes: 2 additions & 2 deletions addons/source-python/packages/source-python/memory/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def fset(ptr, value):
elif type_name == Type.STRING_ARRAY:
if length and len(value.encode()) >= length:
raise ValueError(
'The string length exceeds'
'The string length exceeds '
'the limit "{0}".'.format(length-1))

ptr.set_string_array(value, offset)
Expand Down Expand Up @@ -562,7 +562,7 @@ def fset(ptr, value):
elif type_name == Type.STRING_ARRAY:
if length and len(value.encode()) >= length:
raise ValueError(
'The string length exceeds'
'The string length exceeds '
'the limit "{0}".'.format(length-1))

instance_ptr.set_string_array(value, offset)
Expand Down
11 changes: 8 additions & 3 deletions src/core/modules/memory/memory_pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ const char * CPointer::GetStringPointer(int iOffset /* = 0 */)
return result;
}

void SetStringPointerHelper(unsigned long addr, const char * ptr)
{
TRY_SEGV()
*(const char **) (addr) = ptr;
EXCEPT_SEGV()
}

CPointer * CPointer::SetStringPointer(char * szText, int iOffset /* = 0 */)
{
Validate();
Expand All @@ -121,9 +128,7 @@ CPointer * CPointer::SetStringPointer(char * szText, int iOffset /* = 0 */)
value = szText;
}

TRY_SEGV()
*(const char **) (m_ulAddr + iOffset) = value;
EXCEPT_SEGV()
SetStringPointerHelper(m_ulAddr + iOffset, value);

return new CPointer((unsigned long) value, false);
}
Expand Down