From c900a7dc398f6ba28e3c7e8e40222c63566acdc7 Mon Sep 17 00:00:00 2001
From: Alexandre Fournier <afournier@wazo.io>
Date: Fri, 9 Dec 2022 14:37:13 -0500
Subject: [PATCH] res_geoloc: fix NULL pointer dereference bug

The `ast_geoloc_datastore_add_eprofile` function does not return 0 on
success, it returns the size of the underlying datastore. This means
that the datastore will be freed and its pointer set to NULL when no
error occured at all.

ASTERISK-30346

Change-Id: Iea9b209bd1244cc57b903b9496cb680c356e4bb9
---
 res/res_geolocation/geoloc_datastore.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/res/res_geolocation/geoloc_datastore.c b/res/res_geolocation/geoloc_datastore.c
index 040a9bdcdb..4e7a85e8f1 100644
--- a/res/res_geolocation/geoloc_datastore.c
+++ b/res/res_geolocation/geoloc_datastore.c
@@ -255,7 +255,7 @@ struct ast_datastore *ast_geoloc_datastore_create_from_eprofile(
 	}
 
 	rc = ast_geoloc_datastore_add_eprofile(ds, eprofile);
-	if (rc != 0) {
+	if (rc <= 0) {
 		ast_datastore_free(ds);
 		ds = NULL;
 	}
@@ -297,7 +297,7 @@ struct ast_datastore *ast_geoloc_datastore_create_from_profile_name(const char *
 
 	rc = ast_geoloc_datastore_add_eprofile(ds, eprofile);
 	ao2_ref(eprofile, -1);
-	if (rc != 0) {
+	if (rc <= 0) {
 		ast_datastore_free(ds);
 		ds = NULL;
 	}
-- 
GitLab