Skip to content

Commit db6b937

Browse files
committed
Check for identifier length before removing prefix (refs #363)
1 parent 7b48266 commit db6b937

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

source/glbinding-aux/source/Meta.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ int Meta::glRevision()
4646

4747
size_t Meta::alphabeticalGroupIndex(const std::string & identifier, const std::uint8_t prefixLength)
4848
{
49+
if (identifier.size() < prefixLength) {
50+
return -1;
51+
}
52+
4953
auto index = static_cast<size_t>(identifier[prefixLength]); // ignore prefix ('GL_' or 'gl')
5054

5155
// bold uppercase conversion -> non letters are discarded in next step
@@ -95,6 +99,11 @@ std::set<GLenum> Meta::enums()
9599
GLextension Meta::getExtension(const std::string & glextension)
96100
{
97101
const auto index = alphabeticalGroupIndex(glextension, 3);
102+
103+
if (index >= Meta_ExtensionsByStringMaps.size()) {
104+
return GLextension::UNKNOWN;
105+
}
106+
98107
const auto & map = Meta_ExtensionsByStringMaps[index];
99108
const auto i = map.find(glextension);
100109

@@ -195,6 +204,11 @@ const std::string & Meta::getString(const GLextension glextension)
195204
GLbitfield Meta::getBitfield(const std::string & glbitfield)
196205
{
197206
const auto index = alphabeticalGroupIndex(glbitfield, 3);
207+
208+
if (index >= Meta_BitfieldsByStringMaps.size()) {
209+
return static_cast<GLbitfield>(-1);
210+
}
211+
198212
const auto & map = Meta_BitfieldsByStringMaps[index];
199213
const auto i = map.find(glbitfield);
200214

@@ -209,6 +223,11 @@ GLbitfield Meta::getBitfield(const std::string & glbitfield)
209223
GLenum Meta::getEnum(const std::string & glenum)
210224
{
211225
const auto index = alphabeticalGroupIndex(glenum, 3);
226+
227+
if (index >= Meta_EnumsByStringMaps.size()) {
228+
return static_cast<GLenum>(static_cast<unsigned int>(-1));
229+
}
230+
212231
const auto & map = Meta_EnumsByStringMaps[index];
213232
const auto i = map.find(glenum);
214233

@@ -248,6 +267,11 @@ const std::set<GLextension> Meta::extensions(const Version & version)
248267
const std::set<GLextension> Meta::extensions(const std::string & glfunction)
249268
{
250269
const auto index = alphabeticalGroupIndex(glfunction, 2);
270+
271+
if (index >= Meta_ExtensionsByFunctionStringMaps.size()) {
272+
return noneExtensions;
273+
}
274+
251275
const auto & map = Meta_ExtensionsByFunctionStringMaps[index];
252276
const auto i = map.find(glfunction);
253277

0 commit comments

Comments
 (0)