Skip to content
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

Crash in COPY_STRING_TO_CAPI_STRING_VIEW Function in omp-capi Library #2

Open
adriantandara opened this issue Dec 1, 2024 · 1 comment

Comments

@adriantandara
Copy link

I've encountered an issue with the omp-capi library that causes the server to crash when certain functions are used. After debugging, I identified that the root of the problem is the COPY_STRING_TO_CAPI_STRING_VIEW function. Any function that relies on COPY_STRING_TO_CAPI_STRING_VIEW also causes the server to crash.

Steps to Reproduce

  • Manually compile the omp-capi library in the x64 architecture and include it in your project.

  • Use the COPY_STRING_TO_CAPI_STRING_VIEW function directly or indirectly.

For example:

// Example 1: Calling a function that depends on COPY_STRING_TO_CAPI_STRING_VIEW
omp.on("playerConnect", (player) => {
  const version = player.getVersion().version; // Causes the server to crash.
  console.log(`Player version: ${version}`);
})
  • Observe that the server crashes consistently whenever the function is invoked.
@adriantandara
Copy link
Author

adriantandara commented Dec 2, 2024

I've identified the problem with the function. I tried to fix it myself, but the issue was with the buffer, as it was exceeding the allocated limit.

OMP_CAPI(Player_GetName, int(objectPtr player, OutputStringViewPtr name))
{
    POOL_ENTITY_RET(players, IPlayer, player, player_, 0);

    auto result = player_->getName();
    int len = result.length();

    if (!name) return len;

    if (name->data == nullptr || name->len < len) {
	delete[] name->data;
		
	name->data = new(std::nothrow) char[len];

	if (name->data == nullptr) return -3;

	name->len = len;
    }

    memcpy(name->data, result.data(), len);
    return len;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant