工作中遇到的一个bug:web前台下发非ip地址导致web退出登录
增加后台对ip地址的合法性校验
1 #include <regex> 2 static bool IsIp(const char *ip) { 3 if (ip == NULL) { 4 return false; 5 } 6 std::regex pattern("(?=(\\b|\\D))(((\\d{1,2})|(1\\d{1,2})|(2[0-4]\\d)|(25[0-5]))\\.){3}((\\d{1,2})|(1\\d{1,2})|(2[0-4]\\d)|(25[0-5]))(?=(\\b|\\D))"); 7 if (std::regex_match(ip, pattern)) { 8 return true; 9 } 10 return false; 11 }