On Sat, 2009-08-08 at 23:02 +0200, Kristof Willaert wrote:
> I ran it with the following result:
> 
> $ augtool print
> FILTER: Aliases
>   glob(/etc/aliases, pathc=1) = 0
>   0 matches
> FILTER: Sudoers
>   glob(/etc/sudoers, pathc=1) = 0
>   fnmatch(*.augnew, sudoers, pathc=1) = 1
>   fnmatch(*.augsave, sudoers, pathc=1) = 1
>   fnmatch(*.rpmsave, sudoers, pathc=1) = 1
>   fnmatch(*.rpmnew, sudoers, pathc=1) = 1
>   fnmatch(*~, sudoers, pathc=1) = 1
>   0 matches

It seems that the REALLOC_N is failing, and it looks that that's the
case because Augeas assumes that the pathv in a glob_t is allocated in a
specific manner. Even if this doesn't fix your issue, it needs to be
done. Can you try the attached patch (on top of the previous two) and
let me know if that fixes your issue ?

David

>From 52b2627ace77678ae6994d0d3be921e8ccae9009 Mon Sep 17 00:00:00 2001
From: David Lutterkort <[email protected]>
Date: Mon, 10 Aug 2009 17:30:11 -0700
Subject: [PATCH 3/3] Do not assume how glob allocates gl_pathv

We assumed that the gl_pathv in a glob_t was allocated in a particular
manner; that lead to issues on AIX.

  * src/transform.c (filter_generate): make a copy of gl_pathv
---
 src/transform.c |   55 +++++++++++++++++++++++++++++++++----------------------
 1 files changed, 33 insertions(+), 22 deletions(-)

diff --git a/src/transform.c b/src/transform.c
index 768e545..09847cf 100644
--- a/src/transform.c
+++ b/src/transform.c
@@ -127,47 +127,58 @@ static int filter_generate(struct tree *xfm, const char *root,
 
         if (r != 0 && r != GLOB_NOMATCH) {
             ret = -1;
-            goto done;
+            goto error;
         }
         gl_flags |= GLOB_APPEND;
     }
 
-    char **pathv = globbuf.gl_pathv;
-    int pathc = globbuf.gl_pathc;
-    globbuf.gl_pathv = NULL;
-    globbuf.gl_pathc = 0;
+    char **pathv = NULL;
+    int pathc = globbuf.gl_pathc, pathind = 0;
+
+    if (ALLOC_N(pathv, pathc) < 0)
+        goto error;
+
+    for (int i=0; i < pathc; i++) {
+        const char *path = globbuf.gl_pathv[i];
+        bool include = true;
+
+        list_for_each(e, xfm->children) {
+            if (! is_excl(e))
+                continue;
 
-    list_for_each(e, xfm->children) {
-        if (! is_excl(e))
-            continue;
-        for (int i=0; i < pathc;) {
-            const char *path = pathv[i];
             if (strchr(e->value, SEP) == NULL)
                 path = pathbase(path);
             if ((r = fnmatch(e->value, path, fnm_flags)) == 0) {
-                free(pathv[i]);
-                pathc -= 1;
-                if (i < pathc) {
-                    pathv[i] = pathv[pathc];
-                }
-            } else {
-                i += 1;
+                include = false;
             }
             fprintf(stderr, "  fnmatch(%s, %s, pathc=%d) = %d\n",
                     e->value, path, pathc, r);
         }
+        if (include) {
+            pathv[pathind] = strdup(globbuf.gl_pathv[i]);
+            if (pathv[pathind] == NULL)
+                goto error;
+            pathind += 1;
+        }
     }
-    if (REALLOC_N(pathv, pathc) == -1) {
-        FREE(pathv);
-        pathc = 0;
-        ret = -1;
-    }
+    pathc = pathind;
+
+    if (REALLOC_N(pathv, pathc) == -1)
+        goto error;
+
     fprintf(stderr, "  %d matches\n", pathc);
     *matches = pathv;
     *nmatches = pathc;
  done:
     globfree(&globbuf);
     return ret;
+ error:
+    if (pathv != NULL)
+        for (int i=0; i < pathc; i++)
+            free(pathv[i]);
+    free(pathv);
+    ret = -1;
+    goto done;
 }
 
 static int filter_matches(struct tree *xfm, const char *path) {
-- 
1.6.2.2

_______________________________________________
augeas-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/augeas-devel

Reply via email to