From 294184c8f93e2801df00e3a52d58bc505fc1333d Mon Sep 17 00:00:00 2001
From: Jakob Olsson <jakobols@kth.se>
Date: Fri, 8 Jun 2018 12:47:32 +0200
Subject: [PATCH] Logical flaw to current_apn fix

---
 libmobile_zte.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/libmobile_zte.c b/libmobile_zte.c
index 645eeb4..9840f35 100644
--- a/libmobile_zte.c
+++ b/libmobile_zte.c
@@ -430,8 +430,8 @@ struct json_object *mobile_get_roam_status_zte(char *ip_addr)
 
 struct json_object *mobile_get_current_apn_zte(char *ip_addr)
 {
-	struct json_object *idx_json, *apn_profiles, *current_profile;
-	int idx, counter = 0;
+	struct json_object *current_idx, *idx_json, *apn_profiles, *current_profile;
+	int idx, counter = 0, rv;
 
 	idx_json = prepare_request(ip_addr, "Current_index", GET);
 	if (!idx_json) {
@@ -439,7 +439,12 @@ struct json_object *mobile_get_current_apn_zte(char *ip_addr)
 		goto fail;
 	}
 
-	idx = json_object_get_int(idx_json);
+	json_object_object_get_ex(idx_json, "Current_index", &current_idx);
+	if (!current_idx) {
+		//debug_print("no current idx in response!\n");
+		goto fail_idx;
+	}
+	idx = json_object_get_int(current_idx);
 	if (idx < 0 || idx > 9) {
 		//debug_print("Something is very wrong!\n");
 		goto fail_idx;
@@ -448,7 +453,7 @@ struct json_object *mobile_get_current_apn_zte(char *ip_addr)
 
 	json_object_object_foreach(apn_profiles, key, val) {
 		counter++;
-		if (counter < idx)
+		if (counter <= idx)
 			continue;
 		current_profile = json_object_get(val);
 		break;
-- 
GitLab