Fix sscanf validation usage (field count instead of null_byte == 0)

This commit is contained in:
Vitaliy Filippov
2023-09-07 02:34:35 +03:00
parent 85e9f67d9d
commit b7d398be5b
10 changed files with 36 additions and 36 deletions
+2 -2
View File
@@ -19,8 +19,8 @@ bool string_to_addr(std::string str, bool parse_port, int default_port, struct s
if (p != std::string::npos && !(str.length() > 0 && str[p-1] == ']')) // "[ipv6]" which contains ':'
{
char null_byte = 0;
int n = sscanf(str.c_str()+p+1, "%d%c", &default_port, &null_byte);
if (n != 1 || default_port >= 0x10000)
int scanned = sscanf(str.c_str()+p+1, "%d%c", &default_port, &null_byte);
if (scanned != 1 || default_port >= 0x10000)
return false;
str = str.substr(0, p);
}