Skip to content

Commit d61323b

Browse files
committed
validate arg indirect attribute before indexing direction array
1 parent 27eed5e commit d61323b

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

lib/library.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,8 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
932932
}
933933
if (const char* const argIndirect = functionnode->Attribute("indirect")) {
934934
const int indirect = strToInt<int>(argIndirect);
935+
if (indirect < 0 || indirect >= static_cast<int>(ac.direction.size()))
936+
return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, argIndirect);
935937
ac.direction[indirect] = dir; // TODO: handle multiple directions/indirect levels
936938
}
937939
else

test/testlibrary.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,23 @@ class TestLibrary : public TestFixture {
11561156

11571157
// comma followed by dot
11581158
LOADLIB_ERROR_INVALID_RANGE("-10:0,.5:");
1159+
1160+
// arg indirect out of range (index into ArgumentChecks::direction)
1161+
LOADLIBERROR("<?xml version=\"1.0\"?>\n"
1162+
"<def>\n"
1163+
" <function name=\"foo\">\n"
1164+
" <arg nr=\"1\" direction=\"in\" indirect=\"1000000\"/>\n"
1165+
" </function>\n"
1166+
"</def>",
1167+
Library::ErrorCode::BAD_ATTRIBUTE_VALUE);
1168+
1169+
LOADLIBERROR("<?xml version=\"1.0\"?>\n"
1170+
"<def>\n"
1171+
" <function name=\"foo\">\n"
1172+
" <arg nr=\"1\" direction=\"out\" indirect=\"-5\"/>\n"
1173+
" </function>\n"
1174+
"</def>",
1175+
Library::ErrorCode::BAD_ATTRIBUTE_VALUE);
11591176
}
11601177

11611178
void loadLibCombinations() const {

0 commit comments

Comments
 (0)