Windows: AFSRetrieveParentPath handle no parent
authorJeffrey Altman <jaltman@your-file-system.com>
Tue, 9 Jun 2015 12:44:43 +0000 (08:44 -0400)
committerJeffrey Altman <jaltman@your-file-system.com>
Thu, 24 Sep 2015 04:19:00 +0000 (00:19 -0400)
AFSRetrieveParentPath() when presented with a relative path that has no
parent will walk off the front of the FullFileName buffer.  Add checks to
ensure that Length never becomes less than zero.

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

src/WINNT/afsrdr/kernel/lib/AFSGeneric.cpp

index f2ea340..2594416 100644 (file)
@@ -9117,12 +9117,14 @@ AFSRetrieveParentPath( IN UNICODE_STRING *FullFileName,
     // If the final character is a \, jump over it
     //
 
-    if( ParentPath->Buffer[ (ParentPath->Length/sizeof( WCHAR)) - 1] == L'\\')
+    if( ParentPath->Length >= sizeof( WCHAR)
+       && ParentPath->Buffer[ (ParentPath->Length/sizeof( WCHAR)) - 1] == L'\\')
     {
         ParentPath->Length -= sizeof( WCHAR);
     }
 
-    while( ParentPath->Buffer[ (ParentPath->Length/sizeof( WCHAR)) - 1] != L'\\')
+    while( ParentPath->Length >= sizeof( WCHAR)
+          && ParentPath->Buffer[ (ParentPath->Length/sizeof( WCHAR)) - 1] != L'\\')
     {
         ParentPath->Length -= sizeof( WCHAR);
     }
@@ -9131,7 +9133,10 @@ AFSRetrieveParentPath( IN UNICODE_STRING *FullFileName,
     // And the separator
     //
 
-    ParentPath->Length -= sizeof( WCHAR);
+    if ( ParentPath->Length >= sizeof( WCHAR))
+    {
+       ParentPath->Length -= sizeof( WCHAR);
+    }
 
     return;
 }