1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Fix kernel string copy from user-space.

This commit is contained in:
Jonas 'Sortie' Termansen 2015-10-09 15:19:33 +02:00
parent 2727d9fb50
commit 7c6e6ef317

View file

@ -46,7 +46,7 @@
namespace Sortix { namespace Sortix {
static bool IsInProgressAddressSpace(Process* process) static bool IsInProcessAddressSpace(Process* process)
{ {
addr_t current_address_space; addr_t current_address_space;
#if defined(__i386__) #if defined(__i386__)
@ -80,7 +80,7 @@ bool CopyToUser(void* userdst_ptr, const void* ksrc_ptr, size_t count)
uintptr_t ksrc = (uintptr_t) ksrc_ptr; uintptr_t ksrc = (uintptr_t) ksrc_ptr;
bool result = true; bool result = true;
Process* process = CurrentProcess(); Process* process = CurrentProcess();
assert(IsInProgressAddressSpace(process)); assert(IsInProcessAddressSpace(process));
kthread_mutex_lock(&process->segment_lock); kthread_mutex_lock(&process->segment_lock);
while ( count ) while ( count )
{ {
@ -110,7 +110,7 @@ bool CopyFromUser(void* kdst_ptr, const void* usersrc_ptr, size_t count)
uintptr_t usersrc = (uintptr_t) usersrc_ptr; uintptr_t usersrc = (uintptr_t) usersrc_ptr;
bool result = true; bool result = true;
Process* process = CurrentProcess(); Process* process = CurrentProcess();
assert(IsInProgressAddressSpace(process)); assert(IsInProcessAddressSpace(process));
kthread_mutex_lock(&process->segment_lock); kthread_mutex_lock(&process->segment_lock);
while ( count ) while ( count )
{ {
@ -158,7 +158,7 @@ bool ZeroUser(void* userdst_ptr, size_t count)
uintptr_t userdst = (uintptr_t) userdst_ptr; uintptr_t userdst = (uintptr_t) userdst_ptr;
bool result = true; bool result = true;
Process* process = CurrentProcess(); Process* process = CurrentProcess();
assert(IsInProgressAddressSpace(process)); assert(IsInProcessAddressSpace(process));
kthread_mutex_lock(&process->segment_lock); kthread_mutex_lock(&process->segment_lock);
while ( count ) while ( count )
{ {
@ -189,10 +189,11 @@ char* GetStringFromUser(const char* usersrc_str)
uintptr_t usersrc = (uintptr_t) usersrc_str; uintptr_t usersrc = (uintptr_t) usersrc_str;
size_t result_length = 0; size_t result_length = 0;
Process* process = CurrentProcess(); Process* process = CurrentProcess();
assert(IsInProgressAddressSpace(process)); assert(IsInProcessAddressSpace(process));
kthread_mutex_lock(&process->segment_lock); kthread_mutex_lock(&process->segment_lock);
while ( true ) bool done = false;
while ( !done )
{ {
uintptr_t current_at = usersrc + result_length; uintptr_t current_at = usersrc + result_length;
struct segment* segment = FindSegment(process, current_at); struct segment* segment = FindSegment(process, current_at);
@ -208,12 +209,12 @@ char* GetStringFromUser(const char* usersrc_str)
{ {
char c = str[length]; char c = str[length];
if ( c == '\0' ) if ( c == '\0' )
{
done = true;
break; break;
length++; }
} }
result_length += length; result_length += length;
if ( length < segment_available )
break;
} }
char* result = new char[result_length + 1]; char* result = new char[result_length + 1];