]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Windows: Parse Freelance entries and enforce trailing dot but no trailing ws
authorJeffrey Altman <jaltman@your-file-system.com>
Sat, 14 Aug 2010 00:58:43 +0000 (20:58 -0400)
committerJeffrey Altman <jaltman@openafs.org>
Mon, 16 Aug 2010 03:55:31 +0000 (20:55 -0700)
Make sure that there is a trailing dot and no trailing whitespace
for both Mount Point and Symlink entries read from the Freelance
registry key.

LICENSE MIT

Change-Id: I339d1bd2a8fc3e5f44362c65e872396adf64fdf6
Reviewed-on: http://gerrit.openafs.org/2555
Tested-by: Jeffrey Altman <jaltman@openafs.org>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>
src/WINNT/afsd/cm_freelance.c

index 4a4a84a35fa9a0ff10d5853ea5d603d8beaaaf98..59bd6bcb401a8fdda626404bc1787c8c24fd2e7a 100644 (file)
@@ -492,6 +492,57 @@ int cm_reInitLocalMountPoints() {
     return 0;
 }
 
+/*
+ * cm_enforceTrailingDot
+ *
+ * return 0 on failure, non-zero on success
+ *
+ */
+static int
+cm_enforceTrailingDot(char * line, size_t cchLine, DWORD *pdwSize)
+{
+    if (line[(*pdwSize)-1] == '\0' && line[(*pdwSize)-2] != '.') {
+        /* remove trailing whitespace */
+        while (isspace(line[(*pdwSize)-2])) {
+            line[(*pdwSize)-2] = '\0';
+            (*pdwSize)--;
+        }
+
+        if ((*pdwSize) >= cchLine) {
+            afsi_log("no room for trailing dot");
+            return 0;
+        }
+        line[(*pdwSize)-1] = '.';
+        line[(*pdwSize)] = '\0';
+    } else if (line[(*pdwSize)-1] != '\0' && line[(*pdwSize)-1] != '.') {
+        /* remove trailing whitespace */
+        while (isspace(line[(*pdwSize)-1])) {
+            line[(*pdwSize)-1] = '\0';
+            (*pdwSize)--;
+        }
+
+        if ((*pdwSize) >= cchLine) {
+            afsi_log("no room for trailing dot and nul");
+            return 0;
+        }
+        line[(*pdwSize)] = '.';
+        line[(*pdwSize)+1] = '\0';
+    } else if (line[(*pdwSize)-1] != '\0') {
+        /* remove trailing whitespace */
+        while (isspace(line[(*pdwSize)-1])) {
+            line[(*pdwSize)-1] = '\0';
+            (*pdwSize)--;
+        }
+
+        if ((*pdwSize) >= cchLine) {
+            afsi_log("no room for trailing nul");
+            return 0;
+        }
+        line[(*pdwSize)] = '\0';
+    }
+    return 1;
+}
+
 
 // yj: open up the registry and read all the local mount 
 // points that are stored there. Part of the initialization
@@ -600,12 +651,13 @@ long cm_InitLocalMountPoints() {
                 continue;
             }
 
-            afsi_log("Mountpoint[%d] = %s",dwIndex, line);
+            /* make sure there is a trailing dot and a nul terminator */
+            if (!cm_enforceTrailingDot(line, sizeof(line), &dwSize)) {
+                cm_noLocalMountPoints--;
+                continue;
+            }
 
-            /* find the trailing dot; null terminate after it */
-            t2 = strrchr(line, '.');
-            if (t2)
-                *(t2+1) = '\0';
+            afsi_log("Mountpoint[%d] = %s", dwIndex, line);
 
             for ( t=line;*t;t++ ) {
                 if ( !isprint(*t) ) {
@@ -657,12 +709,13 @@ long cm_InitLocalMountPoints() {
                 continue;
             }
 
-            afsi_log("Symlink[%d] = %s",dwIndex, line);
+            /* make sure there is a trailing dot and a nul terminator */
+            if (!cm_enforceTrailingDot(line, sizeof(line), &dwSize)) {
+                cm_noLocalMountPoints--;
+                continue;
+            }
 
-            /* find the trailing dot; null terminate after it */
-            t2 = strrchr(line, '.');
-            if (t2)
-                *(t2+1) = '\0';
+            afsi_log("Symlink[%d] = %s", dwIndex, line);
 
             for ( t=line;*t;t++ ) {
                 if ( !isprint(*t) ) {