HFP: TWS+: Fix KW issue while parsing QBC

Fix KW issue while parsing QBC

Change-Id: I9de28b72d9c262735ff6ce14858a76e20e2eaff1
diff --git a/system_bt_ext/bta/tws_plus/ag/bta_ag_twsp_dev.cc b/system_bt_ext/bta/tws_plus/ag/bta_ag_twsp_dev.cc
index 7068c15..ecc6e81 100644
--- a/system_bt_ext/bta/tws_plus/ag/bta_ag_twsp_dev.cc
+++ b/system_bt_ext/bta/tws_plus/ag/bta_ag_twsp_dev.cc
@@ -606,15 +606,23 @@
         for (p = p_s; *p != ',' && *p != 0; p++)
         ;
 
-        /* get integer value */
-        *p = 0;
-        n[i] = utl_str2int(p_s);
-        p_s = p + 1;
-        if (p_s == 0) {
+        if (*p == 0) {
+            n[i] = utl_str2int(p_s);
             break;
+        } else {
+            /* get integer value */
+            *p = 0;
+            n[i] = utl_str2int(p_s);
+            p_s = p + 1;
         }
     }
 
+    if (i != 1) {
+        //String doesn't have two parts with a comma delimiter
+        APPL_TRACE_ERROR("%s: Invalid QBC string", __func__);
+        return false;
+    }
+
     /* process values */
     if (n[0] < TWSPLUS_MIN_BATTERY_CHARGE_STATE_CHARGING ||
       n[0] > TWSPLUS_MAX_BATTERY_CHARGE) {