From 7f4310c724bf8ff9458829b19e1b11219430ea96 Mon Sep 17 00:00:00 2001
From: dprice <dprice@users.savannah.nongnu.org>
Date: Tue, 4 Aug 2009 11:03:28 +0000
Subject: [PATCH] * parseinfo.c (parse_config): Find alternate config files
 correctly.

---
 src/ChangeLog   |  4 ++++
 src/parseinfo.c | 33 ++++++++++++++++++++++++++++-----
 2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 0fbbb8625..dd2e2cc14 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2009-08-03  Derek R. Price  <derek@ximbiot.com>
+
+	* parseinfo.c (parse_config): Find alternate config files correctly.
+
 2009-07-18  Derek R. Price  <derek@ximbiot.com>
 
 	* subr.c (sleep_past): Don't assume that time() called after
diff --git a/src/parseinfo.c b/src/parseinfo.c
index 59f33f18c..6743b939d 100644
--- a/src/parseinfo.c
+++ b/src/parseinfo.c
@@ -19,6 +19,9 @@
 /* Verify interface.  */
 #include "parseinfo.h"
 
+/* GNULIB includes.  */
+#include "quote.h"
+
 /* CVS includes.  */
 #include "history.h"
 #include "logmsg.h"
@@ -441,13 +444,33 @@ parse_config (const char *cvsroot, const char *path)
 	{
 	    char *nprefix;
 
+	    /* Allowed prefix == "/" is a special case.  */
+	    if (STREQ (*prefix, "/")) {
+		approved = true;
+		break;
+	    }
+
 	    if (!isreadable (*prefix)) continue;
 	    nprefix = xcanonicalize_file_name (*prefix);
-	    if (STRNEQ (nprefix, npath, strlen (nprefix))
-		&& (((*prefix)[strlen (*prefix)] != '/'
-		     && strlen (npath) == strlen (nprefix))
-		    || ((*prefix)[strlen (*prefix)] == '/'
-			&& npath[strlen (nprefix)] == '/')))
+	    if (/* Strings equal to length of allowed prefix.  */
+		STRNEQ (nprefix, npath, strlen (nprefix))
+		&& (   /* The allowed prefix specifies a file (it does not have
+			* a trailing slash).
+			*/
+		       (*prefix)[strlen (*prefix) - 1] != '/'
+		       /* ...and has the same length as the user specified file
+			* (which means it is an exact match since it matched to
+			* the length of nprefix, above).
+			*/
+		       && strlen (npath) == strlen (nprefix)
+		    || /* The allowed prefix specifies a directory (it has a
+			* trailing slash).
+			*/
+		       (*prefix)[strlen (*prefix) - 1] == '/'
+		       /* ...and the user specified path is under the tree
+			* specified by prefix.
+			*/
+		       && npath[strlen (nprefix)] == '/'))
 		approved = true;
 	    free (nprefix);
 	    if (approved) break;
-- 
GitLab