Skip to content

Commit 5066ddd

Browse files
committed
Removed isdigit
1 parent ce42c18 commit 5066ddd

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

lib/PgSQL_Session.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5306,19 +5306,14 @@ int32_t PgSQL_Session::extract_pid_from_param(const PgSQL_Param_Value& param, ui
53065306
// Convert text to integer
53075307
std::string str_val(reinterpret_cast<const char*>(param.value), param.len);
53085308

5309-
// Validate that the string contains only digits
5310-
for (size_t i = 0; i < str_val.size(); i++) {
5311-
if (!isdigit(str_val[i])) {
5312-
return -1;
5313-
}
5314-
}
5315-
5316-
// Parse the integer
5309+
// Parse the integer (allow leading +/- and whitespace, then validate semantics)
53175310
char* endptr;
5311+
errno = 0;
53185312
long pid = strtol(str_val.c_str(), &endptr, 10);
5319-
5320-
// Check for conversion errors
5321-
if (endptr != str_val.c_str() + str_val.size()) {
5313+
5314+
// Require full consumption (ignoring trailing whitespace)
5315+
while (endptr && *endptr && isspace(static_cast<unsigned char>(*endptr))) endptr++;
5316+
if (endptr == str_val.c_str() || (endptr && *endptr) || errno == ERANGE) {
53225317
return -1;
53235318
}
53245319

0 commit comments

Comments
 (0)