[augeas-devel] [PATCH] Fix segfault when aug_get was passed a "/"
David Lutterkort
dlutter at redhat.com
Fri Apr 25 17:43:23 UTC 2008
# HG changeset patch
# User David Lutterkort <dlutter at redhat.com>
# Date 1209145384 25200
# Node ID 336a984454eee99284ed98daa8610775c8e17b3d
# Parent 07914400e85cc8ce88a338f5f587784549144018
Fix segfault when aug_get was passed a "/"
In that case, make_path returns NULL, which must be checked.
The bigger question, why "/" is not a valid path is a little more subtle:
the tree is really edge-labeled, not node-labeled, i.e. a label applies to
the edge going from a parent to its child, but root has no parent, and
therefore "/" does not really make sense.
diff -r 07914400e85c -r 336a984454ee src/augeas.c
--- a/src/augeas.c Fri Apr 25 09:24:37 2008 -0700
+++ b/src/augeas.c Fri Apr 25 10:43:04 2008 -0700
@@ -535,6 +535,9 @@ int aug_get(const struct augeas *aug, co
struct path *p = make_path(aug->tree, path);
int r;
+ if (p == NULL)
+ return -1;
+
if (value != NULL)
*value = NULL;
@@ -758,6 +761,9 @@ int aug_match(const struct augeas *aug,
}
p = make_path(aug->tree, pathin);
+ if (p == NULL)
+ return -1;
+
for (tree = path_first(p); tree != NULL; tree = path_next(p)) {
if (! TREE_HIDDEN(tree))
cnt += 1;
diff -r 07914400e85c -r 336a984454ee tests/get-root.rb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/get-root.rb Fri Apr 25 10:43:04 2008 -0700
@@ -0,0 +1,4 @@
+# This used to segfault
+commands="
+get /
+"
More information about the augeas-devel
mailing list