Moved the check for max depth when processing an Include
 directive, to avoid doing the glob process for nothing.
 Added file & line number in max depth error message.

Signed-off-by: Olivier Brunel <[email protected]>
---
 src/pacman/conf.c |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 09749ea..2ff16d2 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -700,13 +700,6 @@ static int _parseconfig(const char *file, struct
section_t *section,
        int ret = 0;
        const int max_depth = 10;

-       if(depth >= max_depth) {
-               pm_printf(ALPM_LOG_ERROR,
-                               _("config parsing exceeded max recursion depth 
of %d.\n"), max_depth);
-               ret = 1;
-               goto cleanup;
-       }
-
        pm_printf(ALPM_LOG_DEBUG, "config: attempting to read file %s\n", file);
        fp = fopen(file, "r");
        if(fp == NULL) {
@@ -794,6 +787,16 @@ static int _parseconfig(const char *file, struct
section_t *section,
                                ret = 1;
                                goto cleanup;
                        }
+
+                       /* if we've reached max depth, we're done */
+                       if(depth + 1 >= max_depth) {
+                               pm_printf(ALPM_LOG_ERROR,
+                                       _("config file %s, line %d: parsing 
exceeded max recursion depth
of %d.\n"),
+                                       file, linenum, max_depth);
+                               ret = 1;
+                               goto cleanup;
+                       }
+
                        /* Ignore include failures... assume non-critical */
                        globret = glob(value, GLOB_NOCHECK, NULL, &globbuf);
                        switch(globret) {
-- 
1.7.8.3


Reply via email to