Skip to content

Conversation

@fredroy
Copy link
Contributor

@fredroy fredroy commented Jan 29, 2026

unhandled exception from different string calls and replace unsafe calls of string functions

[with-all-tests]


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@fredroy fredroy added pr: fix Fix a bug pr: status to review To notify reviewers to review this pull-request pr: ai-generated Label notifying the reviewers that part or all of the PR has been generated with the help of an AI labels Jan 29, 2026
@fredroy fredroy force-pushed the fix_vulnerabilities_string branch from 0c9de53 to 8d9a23b Compare January 29, 2026 03:53
Copy link
Contributor

@bakpaul bakpaul left a comment

Choose a reason for hiding this comment

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

I think you are going to hate me...

Comment on lines +201 to +202
strncpy( dataFile, value, sizeof(dataFile) - 1 );
dataFile[sizeof(dataFile) - 1] = '\0';
Copy link
Contributor

Choose a reason for hiding this comment

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

Lol, thank's Claude

{
dataFile[lenWithoutExt] = '\0';
strncat( dataFile, "raw", sizeof(dataFile) - lenWithoutExt - 1 );
}
Copy link
Contributor

Choose a reason for hiding this comment

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

So many if without fallback. Maybe an error message somewhere ?

r.name1.clear();
}
else
r.group1 = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

no clear ?

r.name2.clear();
}
else
r.group2 = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

no clear ?

errno = 0;
double val = std::strtod(c.c_str(), &endptr);
if (errno == 0 && endptr != c.c_str())
values.push_back((Real)val);
Copy link
Contributor

Choose a reason for hiding this comment

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

if, no fall back and no message...

Comment on lines +36 to +59
namespace sofa::helper::deque_detail
{
inline bool safeStrToInt(const std::string& s, int& result)
{
char* endptr = nullptr;
errno = 0;
long val = std::strtol(s.c_str(), &endptr, 10);
if (errno != 0 || endptr == s.c_str() || val < INT_MIN || val > INT_MAX)
return false;
result = static_cast<int>(val);
return true;
}

inline bool safeStrToUInt(const std::string& s, unsigned int& result)
{
char* endptr = nullptr;
errno = 0;
unsigned long val = std::strtoul(s.c_str(), &endptr, 10);
if (errno != 0 || endptr == s.c_str() || val > UINT_MAX)
return false;
result = static_cast<unsigned int>(val);
return true;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, this could have eased all of the previous boiling plate code that I reviewed. Could you kindly ask Claude to put that in a util file and use it everywhere instead of the crappy boiling plate code everywhere

Comment on lines +37 to +61
namespace
{
bool safeStrToInt(const std::string& s, int& result)
{
char* endptr = nullptr;
errno = 0;
long val = std::strtol(s.c_str(), &endptr, 10);
if (errno != 0 || endptr == s.c_str() || val < INT_MIN || val > INT_MAX)
return false;
result = static_cast<int>(val);
return true;
}

bool safeStrToUInt(const std::string& s, unsigned int& result)
{
char* endptr = nullptr;
errno = 0;
unsigned long val = std::strtoul(s.c_str(), &endptr, 10);
if (errno != 0 || endptr == s.c_str() || val > UINT_MAX)
return false;
result = static_cast<unsigned int>(val);
return true;
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Claude, c'mon man

}
catch (const std::exception&)
{
// Skip invalid entries
Copy link
Contributor

Choose a reason for hiding this comment

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

message

errno = 0;
long parsed = std::strtol(str, &endptr, 10);
if (errno != 0 || endptr == str)
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

message

errno = 0;
long val1 = std::strtol(params[0].c_str(), &endptr, 10);
if (errno != 0 || endptr == params[0].c_str() || val1 < INT_MIN || val1 > INT_MAX)
val1 = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

message

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

Labels

pr: ai-generated Label notifying the reviewers that part or all of the PR has been generated with the help of an AI pr: fix Fix a bug pr: status to review To notify reviewers to review this pull-request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants