17
17
18
18
#include < iostream>
19
19
#include < string>
20
+ #include < charconv>
20
21
21
22
#include " modsecurity/transaction.h"
22
23
#include " modsecurity/rule.h"
@@ -28,15 +29,25 @@ namespace actions {
28
29
bool RuleId::init (std::string *error) {
29
30
std::string a = m_parser_payload;
30
31
31
- try {
32
- m_ruleId = std::stod (a);
33
- } catch (...) {
32
+ const auto format = std::chars_format::fixed;
33
+ const auto conv_res = std::from_chars (a.data (), a.data () + a.size (), m_ruleId, format);
34
+ if (conv_res.ec == std::errc::invalid_argument || conv_res.ec == std::errc::result_out_of_range) {
35
+ // Conversion error
34
36
m_ruleId = 0 ;
35
37
error->assign (" The input \" " + a + " \" does not " \
36
38
" seems to be a valid rule id." );
37
39
return false ;
38
40
}
39
41
42
+ // try {
43
+ // m_ruleId = std::stod(a);
44
+ // } catch (...) {
45
+ // m_ruleId = 0;
46
+ // error->assign("The input \"" + a + "\" does not " \
47
+ // "seems to be a valid rule id.");
48
+ // return false;
49
+ // }
50
+
40
51
std::ostringstream oss;
41
52
oss << std::setprecision (40 ) << m_ruleId;
42
53
if (a != oss.str () || m_ruleId < 0 ) {
0 commit comments