Windows: drive mapping enumeration infinite loop
authorJeffrey Altman <jaltman@your-file-system.com>
Fri, 15 Mar 2013 17:07:21 +0000 (13:07 -0400)
committerJeffrey Altman <jaltman@your-file-system.com>
Sat, 16 Mar 2013 22:09:21 +0000 (15:09 -0700)
If WNetEnumResource returns an error as opposed to success, such as
ERROR_UNEXP_NET_ERR, the enumeration loop would retry forever passing
zero for 'cEntries' which in turn results in a successful response
containing zero entries.

Change the while conditional to test for continued success instead
of ERROR_NO_MORE_ENTRIES.

Change-Id: I93af73b379aa455de7a8b3264b5178d482bb52b0
Reviewed-on: http://gerrit.openafs.org/9610
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Tested-by: Jeffrey Altman <jaltman@your-file-system.com>

src/WINNT/client_config/drivemap.cpp

index 9e1a7da..cb9a9a2 100644 (file)
@@ -1197,7 +1197,10 @@ void DoUnMapShare(BOOL drivemap) //disconnect drivemap
     _strlwr(szPath);
     lpnrLocal=(LPNETRESOURCE) GlobalAlloc(GPTR,cbBuffer);
     do {
+        /* Reset lpnrLocal and cEntries before each call */
        memset(lpnrLocal,0,cbBuffer);
+        cEntries = -1;
+
        if ((res = WNetEnumResource(hEnum,&cEntries,lpnrLocal,&cbBuffer))==NO_ERROR)
        {
            for (DWORD i=0;i<cEntries;i++)
@@ -1217,7 +1220,7 @@ void DoUnMapShare(BOOL drivemap)  //disconnect drivemap
                }
            }
        }
-    } while (res!=ERROR_NO_MORE_ITEMS);
+    } while (res == NO_ERROR);
     GlobalFree((HGLOBAL)lpnrLocal);
     WNetCloseEnum(hEnum);
 }
@@ -1249,8 +1252,11 @@ BOOL DoMapShareChange(BOOL removeUnknown)
     sprintf(szPath,"\\\\%s\\",szMachine);
     _strlwr(szPath);
     do {
+        /* Reset lpnrLocal and cEntries before each call */
        memset(lpnrLocal,0,cbBuffer);
-       if ((res = WNetEnumResource(hEnum,&cEntries,lpnrLocal,&cbBuffer))==NO_ERROR)
+        cEntries = -1;
+
+        if ((res = WNetEnumResource(hEnum,&cEntries,lpnrLocal,&cbBuffer))==NO_ERROR)
        {
            for (DWORD i=0;i<cEntries;i++)
            {
@@ -1274,7 +1280,7 @@ BOOL DoMapShareChange(BOOL removeUnknown)
              nextname:;
            }
        }
-    } while (res!=ERROR_NO_MORE_ITEMS);
+    } while (res == NO_ERROR);
     GlobalFree((HGLOBAL)lpnrLocal);
     WNetCloseEnum(hEnum);
     sprintf(szPath,"\\\\%s\\all",szMachine);