celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [celix] branch develop updated: Fix for possible null pointer for the modified index in the etcdlib_get_directory function (#134)
Date Mon, 16 Dec 2019 20:37:05 GMT
This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/celix.git


The following commit(s) were added to refs/heads/develop by this push:
     new 6fbcbc1  Fix for possible null pointer for the modified index in the etcdlib_get_directory
function (#134)
6fbcbc1 is described below

commit 6fbcbc169944f9e6e975834c6cb23a8947d512d9
Author: dhbfischer <52166446+dhbfischer@users.noreply.github.com>
AuthorDate: Mon Dec 16 21:36:54 2019 +0100

    Fix for possible null pointer for the modified index in the etcdlib_get_directory function
(#134)
---
 libs/etcdlib/src/etcd.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/libs/etcdlib/src/etcd.c b/libs/etcdlib/src/etcd.c
index 97cc861..a0324de 100644
--- a/libs/etcdlib/src/etcd.c
+++ b/libs/etcdlib/src/etcd.c
@@ -279,13 +279,20 @@ int etcdlib_get_directory(const etcdlib_t *etcdlib, const char* directory,
etcdl
 			fprintf(stderr, "[ETCDLIB] Error: %s in js_root not found", ETCD_JSON_NODE);
 		}
 		if (js_rootnode != NULL) {
-			*modifiedIndex = 0;
-			retVal = etcd_get_recursive_values(js_rootnode, callback, arg, (json_int_t*)modifiedIndex);
+            long long modIndex = 0;
+            long long *ptrModIndex = NULL;
+            if(modifiedIndex != NULL) {
+                *modifiedIndex = 0;
+                ptrModIndex = modifiedIndex;
+            } else {
+                ptrModIndex = &modIndex;
+            }
+            retVal = etcd_get_recursive_values(js_rootnode, callback, arg, (json_int_t*)ptrModIndex);
             long long indexFromHeader = etcd_get_current_index(reply.header);
-            if (indexFromHeader > *modifiedIndex) {
-              *modifiedIndex = indexFromHeader;
+            if (indexFromHeader > *ptrModIndex) {
+              *ptrModIndex = indexFromHeader;
             }
-		} else {
+		} else if (modifiedIndex != NULL) {
 			// Error occurred, retrieve the index of ETCD from the error code
 			js_rootnode = json_object_get(js_root, ETCD_JSON_INDEX);
 			if(js_rootnode) {
@@ -294,7 +301,6 @@ int etcdlib_get_directory(const etcdlib_t *etcdlib, const char* directory,
etcdl
 
 			} else {
 				fprintf(stderr, "[ETCDLIB] Error: index not found in error %s\n", reply.memory);
-
 			}
 
 		}


Mime
View raw message