[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCHv2 02/10] Replace sscanf in nwfilter rule parsing



Parsing is stricter now and doesn't accept trailing characters
after the actual value anymore.
---
 src/conf/nwfilter_conf.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index 876b3ef..fbf6f33 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -1239,7 +1239,7 @@ virNWFilterRuleDetailsParse(virConnectPtr conn ATTRIBUTE_UNUSED,
 
                         case DATATYPE_UINT8:
                             storage_ptr = &item->u.u8;
-                            if (sscanf(prop, "%d", &int_val) == 1) {
+                            if (virStrToLong_i(prop, NULL, 10, &int_val) >= 0) {
                                 if (int_val >= 0 && int_val <= 0xff) {
                                     if (!validator)
                                         *(uint8_t *)storage_ptr = int_val;
@@ -1253,7 +1253,7 @@ virNWFilterRuleDetailsParse(virConnectPtr conn ATTRIBUTE_UNUSED,
 
                         case DATATYPE_UINT16:
                             storage_ptr = &item->u.u16;
-                            if (sscanf(prop, "%d", &int_val) == 1) {
+                            if (virStrToLong_i(prop, NULL, 10, &int_val) >= 0) {
                                 if (int_val >= 0 && int_val <= 0xffff) {
                                     if (!validator)
                                         *(uint16_t *)storage_ptr = int_val;
@@ -1277,7 +1277,7 @@ virNWFilterRuleDetailsParse(virConnectPtr conn ATTRIBUTE_UNUSED,
                         case DATATYPE_IPMASK:
                             storage_ptr = &item->u.u8;
                             if (!virNWIPv4AddressParser(prop, &ipaddr)) {
-                                if (sscanf(prop, "%d", &int_val) == 1) {
+                                if (virStrToLong_i(prop, NULL, 10, &int_val) >= 0) {
                                     if (int_val >= 0 && int_val <= 32) {
                                         if (!validator)
                                             *(uint8_t *)storage_ptr =
@@ -1331,7 +1331,7 @@ virNWFilterRuleDetailsParse(virConnectPtr conn ATTRIBUTE_UNUSED,
                         case DATATYPE_IPV6MASK:
                             storage_ptr = &item->u.u8;
                             if (!virNWIPv6AddressParser(prop, &ipaddr)) {
-                                if (sscanf(prop, "%d", &int_val) == 1) {
+                                if (virStrToLong_i(prop, NULL, 10, &int_val) >= 0) {
                                     if (int_val >= 0 && int_val <= 128) {
                                         if (!validator)
                                             *(uint8_t *)storage_ptr =
@@ -1659,7 +1659,7 @@ virNWFilterRuleParse(virConnectPtr conn,
     ret->priority = MAX_RULE_PRIORITY / 2;
 
     if (prio) {
-        if (sscanf(prio, "%d", (int *)&priority) == 1) {
+        if (virStrToLong_i(prio, NULL, 10, (int *)&priority) >= 0) {
             if ((int)priority >= 0 && priority <= MAX_RULE_PRIORITY)
                 ret->priority = priority;
         }
-- 
1.6.3.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]