Skip to content

Fix buffer overflow in GLBackend#638

Closed
gabrielOFlores wants to merge 0 commit intoOverload-Technologies:mainfrom
gabrielOFlores:main
Closed

Fix buffer overflow in GLBackend#638
gabrielOFlores wants to merge 0 commit intoOverload-Technologies:mainfrom
gabrielOFlores:main

Conversation

@gabrielOFlores
Copy link
Contributor

Description

Fix for Buffer Overflow by limiting the number of integers in GLint:

//GLBackend.cpp

GLint result[4]; // Fixed size of 4

glGetIntegerv(p_parameter, result); // The max size of glGetIntegerv is 4

return static_cast<int>(result[0]);

Related Issue(s)

Fixes #634

Checklist

  • My code follows the project's code style guidelines
  • My changes don't generate new warnings or errors

See also

Why a fixed size of 4?

@adriengivry
Copy link
Member

adriengivry commented Feb 1, 2026

I've been doing some research, and it seems like since OpenGL 3.0, the safest option is to use:

  • glGetBooleani_v() - indexed query, single boolean
  • glGetIntegeri_v() - indexed query, single integer
  • glGetInteger64i_v() - indexed query, single 64-bit integer
  • glGetFloati_v() - indexed query, single float
  • glGetDoublei_v() - indexed query, single double

Since we already have functions using the glGetXi_v() counterparts, it might be worth it to completely remove the following functions:

bool GetBool(uint32_t parameter);
int GetInt(uint32_t parameter);
int64_t GetInt64(uint32_t parameter);
float GetFloat(uint32_t parameter);
double GetDouble(uint32_t parameter);

And update these to have a default index of 0:

bool GetBool(uint32_t parameter, uint32_t p_index = 0);
int GetInt(uint32_t parameter, uint32_t p_index = 0);
int64_t GetInt64(uint32_t parameter, uint32_t p_index = 0);
float GetFloat(uint32_t parameter, uint32_t p_index = 0);
double GetDouble(uint32_t parameter, uint32_t p_index = 0);

Important

I've tested this locally and it didn't work. I must be misunderstanding something in the glGet documentation.
Edit: after re-reading the doc, from my understanding, glGetIntegeri_v() doesn't work with non-indexed parameters, so glGetIntegerv() still need to be used.

Copy link
Member

@adriengivry adriengivry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above.

Note

You can keep this PR open and push the edits to your branch. No need to create a new PR!

Copy link
Member

@adriengivry adriengivry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like you added the dedicated GPU commit to this PR by mistake. Can you revert this commit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Stack smashing (buffer overflow) detected in debug builds

2 participants