From 5066ddd181e92c6a7aec4b57d088f97ea032d214 Mon Sep 17 00:00:00 2001 From: Rahim Kanji Date: Wed, 14 Jan 2026 16:20:32 +0500 Subject: [PATCH] Removed isdigit --- lib/PgSQL_Session.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/PgSQL_Session.cpp b/lib/PgSQL_Session.cpp index aac4326df..14844a2b1 100644 --- a/lib/PgSQL_Session.cpp +++ b/lib/PgSQL_Session.cpp @@ -5306,19 +5306,14 @@ int32_t PgSQL_Session::extract_pid_from_param(const PgSQL_Param_Value& param, ui // Convert text to integer std::string str_val(reinterpret_cast(param.value), param.len); - // Validate that the string contains only digits - for (size_t i = 0; i < str_val.size(); i++) { - if (!isdigit(str_val[i])) { - return -1; - } - } - - // Parse the integer + // Parse the integer (allow leading +/- and whitespace, then validate semantics) char* endptr; + errno = 0; long pid = strtol(str_val.c_str(), &endptr, 10); - - // Check for conversion errors - if (endptr != str_val.c_str() + str_val.size()) { + + // Require full consumption (ignoring trailing whitespace) + while (endptr && *endptr && isspace(static_cast(*endptr))) endptr++; + if (endptr == str_val.c_str() || (endptr && *endptr) || errno == ERANGE) { return -1; }