Skip to content

RPC4GlobalRegistration: functionName not NUL-terminated for max-length uniqueID #6

Description

@Segfaultd

Summary

RPC4GlobalRegistration's constructors copy uniqueID into the fixed GlobalRegistration::functionName buffer without guaranteeing a NUL terminator. A uniqueID whose length equals RPC4_GLOBAL_REGISTRATION_MAX_FUNCTION_NAME_LENGTH (currently 48, see Source/include/mafianet/defines.h:181) fills the buffer with no terminating '\0'.

RPC4::OnAttach() later passes functionName as a const char* into RegisterFunction / RegisterSlot / RegisterBlockingFunction, where RakString::Assign(const char*) calls strlen — reading past the buffer.

Location

Source/src/RPC4Plugin.cpp, all RPC4GlobalRegistration constructors:

for (i=0; uniqueID[i]; i++)
{
    RakAssert(i<=RPC4_GLOBAL_REGISTRATION_MAX_FUNCTION_NAME_LENGTH-1);
    globalRegistrationBuffer[globalRegistrationIndex].functionName[i]=uniqueID[i];
}
// no functionName[i] = '\0'

The RakAssert permits i up to MAX-1, i.e. filling all 48 bytes, and is a no-op in release builds.

Notes

Suggested fix

Tighten the assert to i < MAX-1 and write an explicit terminator after the copy loop, in every constructor:

for (i=0; uniqueID[i]; i++)
{
    RakAssert(i < RPC4_GLOBAL_REGISTRATION_MAX_FUNCTION_NAME_LENGTH-1);
    globalRegistrationBuffer[globalRegistrationIndex].functionName[i]=uniqueID[i];
}
globalRegistrationBuffer[globalRegistrationIndex].functionName[i]='\0';

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions