From a9c904a256cb10be03995e265c8446be87b73284 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Fri, 15 Sep 2017 16:42:05 +0200 Subject: [PATCH] Do not crash with NULL values from aug_get The Augeas documentation states that NULL can be a valid value associated to a note. Hence, make sure to not crash, and return None in case there is a single node with NULL value. Easily reproducible with: let v = Augeas.get aug "/files" in --- augeas-c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/augeas-c.c b/augeas-c.c index f4396cb..b81c2b1 100644 --- a/augeas-c.c +++ b/augeas-c.c @@ -206,11 +206,11 @@ ocaml_augeas_get (value tv, value pathv) int r; r = aug_get (t, path, &val); - if (r == 1) { /* Return Some val */ + if (r == 1 && val) { /* Return Some val */ v = caml_copy_string (val); optv = caml_alloc (1, 0); Field (optv, 0) = v; - } else if (r == 0) /* Return None */ + } else if (r == 0 || !val) /* Return None */ optv = Val_int (0); else if (r == -1) /* Error or multiple matches */ raise_error (t, "Augeas.get"); -- 1.8.3.1