Skip to content

Commit

Permalink
Merge pull request #83 from sashashura/sashashura-patch-1-1
Browse files Browse the repository at this point in the history
Fix Heap-buffer-overflow READ in ODDLParser::OpenDDLParser::parseFloatingLiteral
  • Loading branch information
kimkulling committed Aug 12, 2023
2 parents 3fbbe5e + f09d53e commit 60f2d08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions code/OpenDDLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const char *getTypeToken(Value::ValueType type) {
return Grammar::PrimitiveTypeToken[(size_t)type];
}

static void logInvalidTokenError(char *in, const std::string &exp, OpenDDLParser::logCallback callback) {
static void logInvalidTokenError(const char *in, const std::string &exp, OpenDDLParser::logCallback callback) {
if (callback) {
std::string full(in);
std::string part(full.substr(0, 50));
Expand Down Expand Up @@ -419,8 +419,8 @@ char *OpenDDLParser::parseStructureBody(char *in, char *end, bool &error) {
}

in = lookForNextToken(in, end);
if (*in != '}') {
logInvalidTokenError(in, std::string(Grammar::CloseBracketToken), m_logCallback);
if (in == end || *in != '}') {
logInvalidTokenError(in == end ? "" : in, std::string(Grammar::CloseBracketToken), m_logCallback);
return nullptr;
} else {
//in++;
Expand Down Expand Up @@ -737,7 +737,7 @@ char *OpenDDLParser::parseFloatingLiteral(char *in, char *end, Value **floating,

in = lookForNextToken(in, end);
char *start(in);
while (!isSeparator(*in) && in != end) {
while (in != end && !isSeparator(*in)) {
++in;
}

Expand Down Expand Up @@ -912,10 +912,10 @@ char *OpenDDLParser::parseDataList(char *in, char *end, Value::ValueType type, V
}

in = lookForNextToken(in, end);
if (*in == '{') {
if (in != end && *in == '{') {
++in;
Value *current(nullptr), *prev(nullptr);
while ('}' != *in) {
while (in != end && '}' != *in) {
current = nullptr;
in = lookForNextToken(in, end);
if (Value::ValueType::ddl_ref == type) {
Expand Down Expand Up @@ -973,11 +973,12 @@ char *OpenDDLParser::parseDataList(char *in, char *end, Value::ValueType type, V
}

in = getNextSeparator(in, end);
if (',' != *in && Grammar::CloseBracketToken[0] != *in && !isSpace(*in)) {
if (in == end || (',' != *in && Grammar::CloseBracketToken[0] != *in && !isSpace(*in))) {
break;
}
}
++in;
if (in != end)
++in;
}

return in;
Expand Down
2 changes: 1 addition & 1 deletion include/openddlparser/OpenDDLParserUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ inline bool isEndofLine(const T in) {

template <class T>
inline static T *getNextSeparator(T *in, T *end) {
while (!isSeparator(*in) || in == end) {
while (in != end && !isSeparator(*in)) {
++in;
}
return in;
Expand Down

0 comments on commit 60f2d08

Please sign in to comment.